Modify

Struct Modify 

Source
pub struct Modify<T> { /* private fields */ }
Expand description

Modifiable object Implements Deref and DerefMut to access the value and adds a flag to indicate if the object was modified.

§Example

use crate::modify::*;
let mut value = Modify::new(42);
assert_eq!(value.is_modified(), false);
*value = 43;
assert_eq!(value.is_modified(), true);
value.saved();
assert_eq!(value.is_modified(), false);

if you use serde you should use #[serde(flatten)} for your Modify<> attribute to avoid the extra level of indirection.

Implementations§

Source§

impl<T> Modify<T>

Source

pub fn new(value: T) -> Self

Create a new modifiable object.

Source

pub fn saved(&mut self)

Clear the modified flag.

Trait Implementations§

Source§

impl<T: Debug> Debug for Modify<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for Modify<T>

Source§

fn default() -> Modify<T>

Returns the “default value” for a type. Read more
Source§

impl<T> Deref for Modify<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T> DerefMut for Modify<T>

Source§

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

Mutably dereferences the value.
Source§

impl<'de, T> Deserialize<'de> for Modify<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for Modify<T>
where T: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<T> for Modify<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T> Modifiable for Modify<T>

Source§

fn is_modified(&self) -> bool

Return true if the object was modified.
Source§

impl<T: PartialEq> PartialEq for Modify<T>

Source§

fn eq(&self, other: &Modify<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for Modify<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> StructuralPartialEq for Modify<T>

Auto Trait Implementations§

§

impl<T> Freeze for Modify<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Modify<T>
where T: RefUnwindSafe,

§

impl<T> Send for Modify<T>
where T: Send,

§

impl<T> Sync for Modify<T>
where T: Sync,

§

impl<T> Unpin for Modify<T>
where T: Unpin,

§

impl<T> UnwindSafe for Modify<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> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,