1.0.0[−][src]Trait geng::prelude::DerefMut
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
(whereT
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 typeU
.
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);
Required methods
Loading content...Implementations on Foreign Types
impl<T> DerefMut for AssertUnwindSafe<T>
[src]
impl DerefMut for OsString
[src]
impl<'_, T> DerefMut for MutexGuard<'_, T> where
T: ?Sized,
[src]
T: ?Sized,
impl<'_, T> DerefMut for RwLockWriteGuard<'_, T> where
T: ?Sized,
[src]
T: ?Sized,
impl<'_, T> !DerefMut for &'_ T where
T: ?Sized,
[src]
T: ?Sized,
impl<'_, T> DerefMut for &'_ mut T where
T: ?Sized,
[src]
T: ?Sized,
impl<'a, 'f> DerefMut for VaList<'a, 'f> where
'f: 'a,
[src]
'f: 'a,
pub fn deref_mut(&mut self) -> &mut VaListImpl<'f>
[src]
impl<T, A> DerefMut for Box<T, A> where
A: AllocRef,
T: ?Sized,
[src]
A: AllocRef,
T: ?Sized,
impl DerefMut for String
[src]
impl<T> DerefMut for Vec<T>
[src]
impl<'_, T> DerefMut for PeekMut<'_, T> where
T: Ord,
[src]
T: Ord,
impl<T> DerefMut for VertexBuffer<T> where
T: Vertex,
[src]
T: Vertex,
impl<'a, T> DerefMut for XSmartPointer<'a, T>
impl<'a, R, T> DerefMut for MutexGuard<'a, R, T> where
R: 'a + RawMutex,
T: 'a + ?Sized,
R: 'a + RawMutex,
T: 'a + ?Sized,
impl<'a, R, T> DerefMut for MappedRwLockWriteGuard<'a, R, T> where
R: 'a + RawRwLock,
T: 'a + ?Sized,
R: 'a + RawRwLock,
T: 'a + ?Sized,
impl<'a, R, T> DerefMut for RwLockWriteGuard<'a, R, T> where
R: 'a + RawRwLock,
T: 'a + ?Sized,
R: 'a + RawRwLock,
T: 'a + ?Sized,
impl<'a, R, T> DerefMut for MappedMutexGuard<'a, R, T> where
R: 'a + RawMutex,
T: 'a + ?Sized,
R: 'a + RawMutex,
T: 'a + ?Sized,
impl<T, F, S> DerefMut for ScopeGuard<T, F, S> where
F: FnOnce(T),
S: Strategy,
[src]
F: FnOnce(T),
S: Strategy,
impl<A> DerefMut for SmallVec<A> where
A: Array,
A: Array,
impl DerefMut for MmapMut
[src]
impl<T> DerefMut for Owned<T>
impl<'a, T> DerefMut for ShardedLockWriteGuard<'a, T> where
T: ?Sized,
T: ?Sized,
impl<T> DerefMut for CachePadded<T>
impl DerefMut for UnixReady
[src]
impl DerefMut for IoVec
impl<P, Container> DerefMut for ImageBuffer<P, Container> where
Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,
P: Pixel + 'static,
<P as Pixel>::Subpixel: 'static,
[src]
Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,
P: Pixel + 'static,
<P as Pixel>::Subpixel: 'static,
pub fn deref_mut(&mut self) -> &mut <ImageBuffer<P, Container> as Deref>::Target
[src]
impl<L, R> DerefMut for Either<L, R> where
L: DerefMut,
R: DerefMut<Target = <L as Deref>::Target>,
[src]
L: DerefMut,
R: DerefMut<Target = <L as Deref>::Target>,
impl<'_, T> DerefMut for ShardedLockWriteGuard<'_, T> where
T: ?Sized,
T: ?Sized,
impl<T> DerefMut for CachePadded<T>
impl<T> DerefMut for Owned<T> where
T: Pointable + ?Sized,
T: Pointable + ?Sized,
impl DerefMut for BytesMut
[src]
impl<T, N> DerefMut for GenericArray<T, N> where
N: ArrayLength<T>,
N: ArrayLength<T>,
impl<'s, T> DerefMut for SliceVec<'s, T>
impl<A> DerefMut for ArrayVec<A> where
A: Array,
A: Array,
impl<A> DerefMut for TinyVec<A> where
A: Array,
A: Array,
impl<T> DerefMut for SliceDeque<T>
impl<A> DerefMut for TinyVec<A> where
A: Array,
A: Array,
impl<A> DerefMut for ArrayVec<A> where
A: Array,
Loading content...A: Array,
Implementors
impl DerefMut for Error
[src]
impl<'_> DerefMut for Column<'_>
[src]
impl<'_> DerefMut for Row<'_>
[src]
impl<'_> DerefMut for Stack<'_>
[src]
impl<'_, T> DerefMut for geng::prelude::futures::lock::MutexGuard<'_, T> where
T: ?Sized,
[src]
T: ?Sized,
impl<'_, T> DerefMut for RefMut<'_, T> where
T: ?Sized,
[src]
T: ?Sized,
impl<'_, T, U> DerefMut for geng::prelude::futures::lock::MappedMutexGuard<'_, T, U> where
T: ?Sized,
U: ?Sized,
[src]
T: ?Sized,
U: ?Sized,
impl<'a> DerefMut for IoSliceMut<'a>
[src]
impl<P> DerefMut for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Unpin,
[src]
P: DerefMut,
<P as Deref>::Target: Unpin,
impl<S> DerefMut for BlockingStream<S> where
S: Unpin + Stream,
[src]
S: Unpin + Stream,
pub fn deref_mut(&mut self) -> &mut <BlockingStream<S> as Deref>::TargetⓘNotable traits for BlockingStream<S>
impl<S> Iterator for BlockingStream<S> where
S: Unpin + Stream, type Item = <S as Stream>::Item;
[src]
Notable traits for BlockingStream<S>
impl<S> Iterator for BlockingStream<S> where
S: Unpin + Stream, type Item = <S as Stream>::Item;
impl<T> DerefMut for ManuallyDrop<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> DerefMut for AutoSave<T> where
T: Serialize,
[src]
T: Serialize,
impl<T> DerefMut for Color<T> where
T: ColorComponent,
[src]
T: ColorComponent,
impl<T> DerefMut for Vec2<T>
[src]
impl<T> DerefMut for Vec3<T>
[src]
impl<T> DerefMut for Vec4<T>
[src]
impl<T, F> DerefMut for geng::prelude::once_cell::sync::Lazy<T, F> where
F: FnOnce() -> T,
F: FnOnce() -> T,
impl<T, F> DerefMut for geng::prelude::once_cell::unsync::Lazy<T, F> where
F: FnOnce() -> T,
F: FnOnce() -> T,