Struct Modified

Source
pub struct Modified<T>(/* private fields */);
Expand description

Struct that holds value and tracks if it was modified.

Implementations§

Source§

impl<T> Modified<T>

Source

pub fn new(v: T) -> Self

Creates new Modified with v inside.

let m = Modified::new(15);
assert_eq!(*m, 15);
Source

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());
Source

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);
Source

pub fn get(&self) -> &T

Returns a reference to the inner value.

let m = Modified::new(15);
assert_eq!(m.get(), &15);
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());
Source§

impl<T> Modified<T>
where T: Default,

Source

pub fn default_modified() -> Self

Creates new Modified from the default value of T and marks it as it was modified.

Trait Implementations§

Source§

impl<T> Clone for Modified<T>
where T: Clone,

Source§

fn clone(&self) -> Self

Clones inner value with it’s state. That means that if value was changed, cloned will also be marked as changed.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Default for Modified<T>
where T: Default,

Source§

fn default() -> Self

Creates new Modified from default value of T.

Source§

impl<T> Deref for Modified<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for Modified<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Into<Resetable<T>> for Modified<T>

Source§

fn into(self) -> Resetable<T>

Converts this type into the (usually inferred) input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.