Trait druid::piet::cairo::glib::bitflags::_core::ops::DerefMut

1.0.0 · source ·
pub trait DerefMut: Deref {
    // Required method
    fn deref_mut(&mut self) -> &mut Self::Target;
}
Expand description

Used for mutable dereferencing operations, like in *v = 1;.

In addition to being used for explicit dereferencing operations with the (unary) * operator in mutable contexts, DerefMut is also used implicitly by the compiler in many circumstances. This mechanism is called Deref coercion’. In immutable contexts, Deref is used.

Implementing DerefMut for smart pointers makes mutating the data behind them convenient, which is why they implement DerefMut. On the other hand, the rules regarding Deref and DerefMut were designed specifically to accommodate smart pointers. Because of this, DerefMut should only be implemented for smart pointers to avoid confusion.

For similar reasons, this trait should never fail. Failure during dereferencing can be extremely confusing when DerefMut is invoked implicitly.

More on Deref coercion

If T implements DerefMut<Target = U>, and x is a value of type T, then:

  • In mutable contexts, *x (where T is neither a reference nor a raw pointer) is equivalent to *DerefMut::deref_mut(&mut x).
  • Values of type &mut T are coerced to values of type &mut U
  • T implicitly implements all the (mutable) methods of the type U.

For more details, visit the chapter in The Rust Programming Language as well as the reference sections on the dereference operator, method resolution and type coercions.

Examples

A struct with a single field which is modifiable by dereferencing the struct.

use std::ops::{Deref, DerefMut};

struct DerefMutExample<T> {
    value: T
}

impl<T> Deref for DerefMutExample<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.value
    }
}

impl<T> DerefMut for DerefMutExample<T> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.value
    }
}

let mut x = DerefMutExample { value: 'a' };
*x = 'b';
assert_eq!('b', x.value);

Required Methods§

source

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

Mutably dereferences the value.

Implementors§

§

impl DerefMut for ImageSurfaceDataOwned

§

impl DerefMut for ILong

§

impl DerefMut for ULong

§

impl DerefMut for ValueArray

1.3.0 · source§

impl DerefMut for String

1.44.0 · source§

impl DerefMut for OsString

1.68.0 · source§

impl DerefMut for PathBuf

source§

impl DerefMut for Error

§

impl DerefMut for AttrColor

§

impl DerefMut for AttrFloat

§

impl DerefMut for AttrFontDesc

§

impl DerefMut for AttrFontFeatures

§

impl DerefMut for AttrInt

§

impl DerefMut for AttrLanguage

§

impl DerefMut for AttrShape

§

impl DerefMut for AttrSize

§

impl DerefMut for AttrString

§

impl DerefMut for Border

§

impl DerefMut for EventButton

§

impl DerefMut for EventConfigure

§

impl DerefMut for EventCrossing

§

impl DerefMut for EventDND

§

impl DerefMut for EventExpose

§

impl DerefMut for EventFocus

§

impl DerefMut for EventGrabBroken

§

impl DerefMut for EventKey

§

impl DerefMut for EventMotion

§

impl DerefMut for EventOwnerChange

§

impl DerefMut for EventPadAxis

§

impl DerefMut for EventPadButton

§

impl DerefMut for EventPadGroupMode

§

impl DerefMut for EventProperty

§

impl DerefMut for EventProximity

§

impl DerefMut for EventScroll

§

impl DerefMut for EventSelection

§

impl DerefMut for EventSetting

§

impl DerefMut for EventTouch

§

impl DerefMut for EventTouchpadPinch

§

impl DerefMut for EventTouchpadSwipe

§

impl DerefMut for EventVisibility

§

impl DerefMut for EventWindowState

§

impl DerefMut for Key

§

impl DerefMut for Literal

§

impl DerefMut for MmapMut

§

impl<'a> DerefMut for ImageSurfaceData<'a>

1.36.0 · source§

impl<'a> DerefMut for IoSliceMut<'a>

§

impl<'a> DerefMut for Face<'a>

source§

impl<'a, 'f> DerefMut for VaList<'a, 'f>where 'f: 'a,

source§

impl<'a, T, C> DerefMut for sharded_slab::pool::RefMut<'a, T, C>where T: Clear + Default, C: Config,

source§

impl<'c> DerefMut for PaintCtx<'_, '_, 'c>

§

impl<A> DerefMut for SmallVec<A>where A: Array,

§

impl<A, N> DerefMut for Chunk<A, N>where N: ChunkLength<A>,

§

impl<A, T> DerefMut for FixedSizeVariantArray<A, T>where A: AsRef<[T]>, T: FixedSizeVariantType,

§

impl<A, T> DerefMut for InlineArray<A, T>

§

impl<I> DerefMut for SubImage<I>where I: DerefMut,

1.33.0 · source§

impl<P> DerefMut for Pin<P>where P: DerefMut, <P as Deref>::Target: Unpin,

§

impl<P, Container> DerefMut for ImageBuffer<P, Container>where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,

§

impl<S> DerefMut for BlockingStream<S>where S: Stream + Unpin,

source§

impl<T> !DerefMut for &Twhere T: ?Sized,

source§

impl<T> DerefMut for &mut Twhere T: ?Sized,

source§

impl<T> DerefMut for Label<T>

§

impl<T> DerefMut for Class<T>where T: ParentClassIs,

§

impl<T> DerefMut for ClassStruct<T>where T: ObjectSubclass,

source§

impl<T> DerefMut for druid::piet::cairo::glib::bitflags::_core::cell::RefMut<'_, T>where T: ?Sized,

1.20.0 (const: unstable) · source§

impl<T> DerefMut for ManuallyDrop<T>where T: ?Sized,

1.9.0 · source§

impl<T> DerefMut for AssertUnwindSafe<T>

source§

impl<T> DerefMut for ThinBox<T>where T: ?Sized,

1.12.0 · source§

impl<T> DerefMut for PeekMut<'_, T>where T: Ord,

source§

impl<T> DerefMut for std::sync::mutex::MutexGuard<'_, T>where T: ?Sized,

source§

impl<T> DerefMut for RwLockWriteGuard<'_, T>where T: ?Sized,

§

impl<T> DerefMut for MutexGuard<'_, T>where T: ?Sized,

§

impl<T> DerefMut for OwnedMutexGuard<T>where T: ?Sized,

const: unstable · source§

impl<T, A> DerefMut for Box<T, A>where A: Allocator, T: ?Sized,

source§

impl<T, A> DerefMut for Vec<T, A>where A: Allocator,

source§

impl<T, C> DerefMut for OwnedRefMut<T, C>where T: Clear + Default, C: Config,

§

impl<T, F> DerefMut for druid::piet::cairo::glib::once_cell::sync::Lazy<T, F>where F: FnOnce() -> T,

§

impl<T, F> DerefMut for druid::piet::cairo::glib::once_cell::unsync::Lazy<T, F>where F: FnOnce() -> T,

§

impl<T, MM> DerefMut for Boxed<T, MM>where T: 'static, MM: BoxedMemoryManager<T>,

§

impl<T, U> DerefMut for MappedMutexGuard<'_, T, U>where T: ?Sized, U: ?Sized,

source§

impl<T, const CAP: usize> DerefMut for ArrayVec<T, CAP>

source§

impl<const CAP: usize> DerefMut for ArrayString<CAP>