pub struct Modified<T>(/* private fields */);
Expand description
Struct that holds value and tracks if it was modified.
Implementations§
Source§impl<T> Modified<T>
impl<T> Modified<T>
Sourcepub fn new(v: T) -> Self
pub fn new(v: T) -> Self
Creates new Modified
with v
inside.
let m = Modified::new(15);
assert_eq!(*m, 15);
Sourcepub fn new_modified(v: T) -> Self
pub fn new_modified(v: T) -> Self
Creates new Modified
with v
inside and marks it as it was modified.
let m = Modified::new_modified(15);
assert!(m.is_modified());
Sourcepub fn set(&mut self, v: T)
pub fn set(&mut self, v: T)
Destroys previous valus inside Modified
replacing it with the new one.
let mut m = Modified::new(15);
m.set(20);
assert_eq!(*m, 20);
Sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Returns a reference to the inner value.
let m = Modified::new(15);
assert_eq!(m.get(), &15);
Sourcepub fn get_value_changed(&self) -> (&T, bool)
pub fn get_value_changed(&self) -> (&T, bool)
Returns a reference to the inner value and its state.
If value was modified state will be true
otherwise, false
.
let m = Modified::new(15);
assert_eq!(m.get_value_changed(), (&15, false));
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the ownership of the inner value.
#[derive(Debug, PartialEq, Eq)]
struct Owned(i32);
let m = Modified::new(Owned(15));
assert_eq!(m.into_inner(), Owned(15));
Sourcepub fn into_inner_changed(self) -> (T, bool)
pub fn into_inner_changed(self) -> (T, bool)
Returns the ownership of the inner value and its state.
If value was modified state will be true
otherwise, false
.
#[derive(Debug, PartialEq, Eq)]
struct Owned(i32);
let m = Modified::new(Owned(15));
assert_eq!(m.into_inner_changed(), (Owned(15), false));
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Returns true
if the variable inside was modified, otherwise returns false
.
let mut m = Modified::new(15);
*m = 20;
assert!(m.is_modified());
Sourcepub fn is_unchanged(&self) -> bool
pub fn is_unchanged(&self) -> bool
Returns true
if the variable inside wasn’t changed, otherwise returns false
.
let mut m = Modified::new(15);
*m = 20;
assert!(!m.is_unchanged());
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Modified<T>where
T: Freeze,
impl<T> RefUnwindSafe for Modified<T>where
T: RefUnwindSafe,
impl<T> Send for Modified<T>where
T: Send,
impl<T> Sync for Modified<T>where
T: Sync,
impl<T> Unpin for Modified<T>where
T: Unpin,
impl<T> UnwindSafe for Modified<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more