pub struct Leaf<T> {
pub before: T,
pub after: T,
}Expand description
A primitive or atomic change.
T is normally a reference of some kind, but it can be any type.
For more information, see the crate-level documentation.
Fields§
§before: TThe value on the before side.
after: TThe value on the after side.
Implementations§
Source§impl<T> Leaf<T>
impl<T> Leaf<T>
Sourcepub fn as_deref(&self) -> Leaf<&T::Target>where
T: Deref,
pub fn as_deref(&self) -> Leaf<&T::Target>where
T: Deref,
Convert from Leaf<T> or &Leaf<T> to Leaf<&T::Target>.
§Example
use daft::Leaf;
let x: Leaf<String> = Leaf { before: "hello".to_owned(), after: "world".to_owned() };
assert_eq!(x.as_deref(), Leaf { before: "hello", after: "world" });Sourcepub fn as_deref_mut(&mut self) -> Leaf<&mut T::Target>where
T: DerefMut,
pub fn as_deref_mut(&mut self) -> Leaf<&mut T::Target>where
T: DerefMut,
Convert from Leaf<T> or &mut Leaf<T> to Leaf<&mut T::Target>.
§Example
use daft::Leaf;
let mut x: Leaf<String> = Leaf { before: "hello".to_owned(), after: "world".to_owned() };
assert_eq!(
x.as_deref_mut().map(|x| {
x.make_ascii_uppercase();
x
}),
Leaf { before: "HELLO".to_owned().as_mut_str(), after: "WORLD".to_owned().as_mut_str() },
);Sourcepub fn map<U, F>(self, f: F) -> Leaf<U>where
F: FnMut(T) -> U,
pub fn map<U, F>(self, f: F) -> Leaf<U>where
F: FnMut(T) -> U,
Map a Leaf<T> to a Leaf<U> by applying a function to the before
and after values.
f will be called twice: first with before, then with after.
§Example
A Leaf<&str> can be converted to a Leaf<String> by calling map
with String::from:
use daft::{Diffable, Leaf};
let before = "hello";
let after = "world";
let leaf: Leaf<&str> = Leaf { before, after };
let leaf: Leaf<String> = leaf.map(String::from);Sourcepub fn is_unchanged(&self) -> boolwhere
T: Eq,
pub fn is_unchanged(&self) -> boolwhere
T: Eq,
Return true if before is the same as after.
This is the same as self.before == self.after, but is easier to use in
a chained series of method calls.
§Example
use daft::{Diffable, Leaf};
let before = "hello";
let after = "hello";
let leaf: Leaf<&str> = Leaf { before, after };
assert!(leaf.is_unchanged());
let before = "hello";
let after = "world";
let leaf: Leaf<&str> = Leaf { before, after };
assert!(!leaf.is_unchanged());Sourcepub fn is_modified(&self) -> boolwhere
T: Eq,
pub fn is_modified(&self) -> boolwhere
T: Eq,
Return true if before is different from after.
This is the same as self.before != self.after, but is easier to use in
a chained series of method calls.
§Example
use daft::{Diffable, Leaf};
let before = "hello";
let after = "hello";
let leaf: Leaf<&str> = Leaf { before, after };
assert!(!leaf.is_modified());
let before = "hello";
let after = "world";
let leaf: Leaf<&str> = Leaf { before, after };
assert!(leaf.is_modified());Source§impl<T> Leaf<&T>
impl<T> Leaf<&T>
Sourcepub fn cloned(self) -> Leaf<T>where
T: Clone,
pub fn cloned(self) -> Leaf<T>where
T: Clone,
Create a clone of the leaf with owned values.
§Example
use daft::{Diffable, Leaf};
let before = String::from("hello");
let after = String::from("world");
let leaf: Leaf<&String> = Leaf { before: &before, after: &after };
// cloned turns a Leaf<&String> into a Leaf<String>.
let leaf: Leaf<String> = leaf.cloned();
assert_eq!(leaf.before, "hello");
assert_eq!(leaf.after, "world");Sourcepub fn copied(self) -> Leaf<T>where
T: Copy,
pub fn copied(self) -> Leaf<T>where
T: Copy,
Create a copy of the leaf with owned values.
§Example
use daft::{Diffable, Leaf};
let before = "hello";
let after = "world";
let leaf: Leaf<&&str> = Leaf { before: &before, after: &after };
// copied turns a Leaf<&&str> into a Leaf<&str>.
let leaf: Leaf<&str> = leaf.copied();
assert_eq!(leaf.before, "hello");
assert_eq!(leaf.after, "world");