Struct ModificationScope

Source
pub struct ModificationScope<'a, 'b, E, R>
where E: Entry, R: Receiver<E>,
{ /* private fields */ }
Expand description

A drop guard for modifying data bahind a Handle using a mutable reference instead of moving in a new value.

Since Storage should notify a receiver whenever data inside of it is modified, it cannot simply hand out mutable references to the value, because that’d allow outside code to implicitly perform a silent storage modification. While ways to do so are also provided, it’s heavily discouraged and reserved for special cases.

The solution to the problem is this struct: ModificationScope. It’s a drop guard which is created by providing a receiver to the storage. While it has little to no differences to a mutable reference to the data inside in terms of functionality, it notifies the receiver when dropped, ensuring that it will get modified even if a panic or any other kind of early return happens.

Trait Implementations§

Source§

impl<'a, 'b, E, R> AsMut<Handle<'a, E, R>> for ModificationScope<'a, 'b, E, R>
where E: Entry, R: Receiver<E>,

Source§

fn as_mut(&mut self) -> &mut Handle<'a, E, R>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<'a, 'b, E, R> AsRef<Handle<'a, E, R>> for ModificationScope<'a, 'b, E, R>
where E: Entry, R: Receiver<E>,

Source§

fn as_ref(&self) -> &Handle<'a, E, R>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, 'b, E, R> Debug for ModificationScope<'a, 'b, E, R>
where E: Entry, E::Data: Debug, R: Receiver<E> + Debug,

Source§

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

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

impl<'a, 'b, E, R> Deref for ModificationScope<'a, 'b, E, R>
where E: Entry, R: Receiver<E>,

Source§

type Target = <E as Entry>::Data

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'a, 'b, E, R> DerefMut for ModificationScope<'a, 'b, E, R>
where E: Entry, R: Receiver<E>,

Source§

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

Mutably dereferences the value.
Source§

impl<'a, 'b, E, R> Drop for ModificationScope<'a, 'b, E, R>
where E: Entry, R: Receiver<E>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, 'b, E, R> Freeze for ModificationScope<'a, 'b, E, R>

§

impl<'a, 'b, E, R> RefUnwindSafe for ModificationScope<'a, 'b, E, R>

§

impl<'a, 'b, E, R> Send for ModificationScope<'a, 'b, E, R>
where R: Send, <E as Entry>::Data: Send, E: Send,

§

impl<'a, 'b, E, R> Sync for ModificationScope<'a, 'b, E, R>
where R: Sync, <E as Entry>::Data: Sync, E: Sync,

§

impl<'a, 'b, E, R> Unpin for ModificationScope<'a, 'b, E, R>

§

impl<'a, 'b, E, R> !UnwindSafe for ModificationScope<'a, 'b, E, R>

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<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn get_ref_to<E: Entry>(&self) -> &E::Data
where Self: Get<E>,

Returns an unguarded immutable reference to the field.
Source§

fn get_handle_to<E: Entry>( &mut self, ) -> Handle<'_, E, <Self as Get<E>>::Receiver>
where Self: Get<E>,

Returns a Handle to the field.
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.