Debian Codegraph @

src/leaf.rs

raw symbols SCIP
1 use craterust-analyzer cargo daft 0.1.5 crate/::Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable#;
2 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#};
3
4 /// A primitive or atomic change.
5 ///
6 /// `T` is normally a reference of some kind, but it can be any type.
7 ///
8 /// For more information, see the [crate-level documentation](crate).
9 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
10 pub struct Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<T> {
11 /// The value on the before side.
12 pub beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: T,
13
14 /// The value on the after side.
15 pub afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: T,
16 }
17
18 impl<T> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<T> {
19 /// Convert from `&Leaf<T>` to `Leaf<&T>`.
20 #[inline]
21 pub fn as_refrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<T>`]as_ref().(&self) -> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&T> {
22 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: &self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before., afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: &self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after. }
23 }
24
25 /// Convert from `&mut Leaf<T>` to `Leaf<&mut T>`.
26 #[inline]
27 pub fn as_mutrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<T>`]as_mut().(&mut self) -> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&mut T> {
28 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: &mut self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before., afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: &mut self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after. }
29 }
30
31 /// Convert from `Leaf<T>` or `&Leaf<T>` to `Leaf<&T::Target>`.
32 ///
33 /// # Example
34 ///
35 /// ```
36 /// # #[cfg(feature = "std")] {
37 /// use daft::Leaf;
38 ///
39 /// let x: Leaf<String> = Leaf { before: "hello".to_owned(), after: "world".to_owned() };
40 /// assert_eq!(x.as_deref(), Leaf { before: "hello", after: "world" });
41 /// # }
42 /// ```
43 #[inline]
44 pub fn as_derefrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<T>`]as_deref().(&self) -> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&T::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target#>
45 where
46 T: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#,
47 {
48 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before., afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after. }
49 }
50
51 /// Convert from `Leaf<T>` or `&mut Leaf<T>` to `Leaf<&mut T::Target>`.
52 ///
53 /// # Example
54 ///
55 /// ```
56 /// # #[cfg(feature = "std")] {
57 /// use daft::Leaf;
58 ///
59 /// let mut x: Leaf<String> = Leaf { before: "hello".to_owned(), after: "world".to_owned() };
60 /// assert_eq!(
61 /// x.as_deref_mut().map(|x| {
62 /// x.make_ascii_uppercase();
63 /// x
64 /// }),
65 /// Leaf { before: "HELLO".to_owned().as_mut_str(), after: "WORLD".to_owned().as_mut_str() },
66 /// );
67 /// # }
68 /// ```
69 #[inline]
70 pub fn as_deref_mutrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<T>`]as_deref_mut().(&mut self) -> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&mut T::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target#>
71 where
72 T: DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#,
73 {
74 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#deref_mut().self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before., afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#deref_mut().self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after. }
75 }
76
77 /// Map a `Leaf<T>` to a `Leaf<U>` by applying a function to the `before`
78 /// and `after` values.
79 ///
80 /// `f` will be called twice: first with `before`, then with `after`.
81 ///
82 /// # Example
83 ///
84 /// A `Leaf<&str>` can be converted to a `Leaf<String>` by calling `map`
85 /// with `String::from`:
86 ///
87 /// ```
88 /// # #[cfg(feature = "std")] {
89 /// use daft::{Diffable, Leaf};
90 ///
91 /// let before = "hello";
92 /// let after = "world";
93 ///
94 /// let leaf: Leaf<&str> = Leaf { before, after };
95 /// let leaf: Leaf<String> = leaf.map(String::from);
96 /// # }
97 /// ```
98 #[inline]
99 pub fn maprust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<T>`]map().<U, F>(self, mut f: F) -> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<U>
100 where
101 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(T) -> U,
102 {
103 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: f(self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.), afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: f(self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.) }
104 }
105
106 /// Return true if before is the same as after.
107 ///
108 /// This is the same as `self.before == self.after`, but is easier to use in
109 /// a chained series of method calls.
110 ///
111 /// # Example
112 ///
113 /// ```
114 /// use daft::{Diffable, Leaf};
115 ///
116 /// let before = "hello";
117 /// let after = "hello";
118 ///
119 /// let leaf: Leaf<&str> = Leaf { before, after };
120 /// assert!(leaf.is_unchanged());
121 ///
122 /// let before = "hello";
123 /// let after = "world";
124 ///
125 /// let leaf: Leaf<&str> = Leaf { before, after };
126 /// assert!(!leaf.is_unchanged());
127 /// ```
128 #[inline]
129 pub fn is_unchangedrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<T>`]is_unchanged().(&self) -> bool
130 where
131 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
132 {
133 self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.
134 }
135
136 /// Return true if before is different from after.
137 ///
138 /// This is the same as `self.before != self.after`, but is easier to use in
139 /// a chained series of method calls.
140 ///
141 /// # Example
142 ///
143 /// ```
144 /// use daft::{Diffable, Leaf};
145 ///
146 /// let before = "hello";
147 /// let after = "hello";
148 ///
149 /// let leaf: Leaf<&str> = Leaf { before, after };
150 /// assert!(!leaf.is_modified());
151 ///
152 /// let before = "hello";
153 /// let after = "world";
154 ///
155 /// let leaf: Leaf<&str> = Leaf { before, after };
156 /// assert!(leaf.is_modified());
157 /// ```
158 #[inline]
159 pub fn is_modifiedrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<T>`]is_modified().(&self) -> bool
160 where
161 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
162 {
163 self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.
164 }
165 }
166
167 impl<'daft, T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable#> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&'daft T> {
168 /// Perform a diff on [`before`][Self::before] and [`after`][Self::after],
169 /// returning `T::Diff`.
170 ///
171 /// This is useful when `T::Diff` is not a leaf node.
172 #[inline]
173 pub fn diff_pairrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<&'daft T>`]diff_pair().(self) -> T::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft> {
174 self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before..diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#diff().(self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.)
175 }
176 }
177
178 impl<T> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&T> {
179 /// Create a clone of the leaf with owned values.
180 ///
181 /// # Example
182 ///
183 /// ```
184 /// # #[cfg(feature = "std")] {
185 /// use daft::{Diffable, Leaf};
186 ///
187 /// let before = String::from("hello");
188 /// let after = String::from("world");
189 ///
190 /// let leaf: Leaf<&String> = Leaf { before: &before, after: &after };
191 /// // cloned turns a Leaf<&String> into a Leaf<String>.
192 /// let leaf: Leaf<String> = leaf.cloned();
193 /// assert_eq!(leaf.before, "hello");
194 /// assert_eq!(leaf.after, "world");
195 /// # }
196 /// ```
197 #[inline]
198 pub fn clonedrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<&T>`]cloned().(self) -> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<T>
199 where
200 T: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
201 {
202 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() }
203 }
204
205 /// Create a copy of the leaf with owned values.
206 ///
207 /// # Example
208 ///
209 /// ```
210 /// use daft::{Diffable, Leaf};
211 ///
212 /// let before = "hello";
213 /// let after = "world";
214 ///
215 /// let leaf: Leaf<&&str> = Leaf { before: &before, after: &after };
216 /// // copied turns a Leaf<&&str> into a Leaf<&str>.
217 /// let leaf: Leaf<&str> = leaf.copied();
218 /// assert_eq!(leaf.before, "hello");
219 /// assert_eq!(leaf.after, "world");
220 /// ```
221 #[inline]
222 pub fn copiedrust-analyzer cargo daft 0.1.5 leaf/impl#[`Leaf<&T>`]copied().(self) -> Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<T>
223 where
224 T: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#,
225 {
226 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before., afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after. }
227 }
228 }