Trait std::ops::DerefMut
[−]
[src]
pub trait DerefMut: Deref { fn deref_mut(&mut self) -> &mut Self::Target; }
The DerefMut
trait is used to specify the functionality of dereferencing
mutably like *v = 1;
DerefMut
also enables 'Deref
coercions'.
Examples
A struct with a single field which is modifiable via dereferencing the struct.
use std::ops::{Deref, DerefMut}; struct DerefMutExample<T> { value: T } impl<T> Deref for DerefMutExample<T> { type Target = T; fn deref<'a>(&'a self) -> &'a T { &self.value } } impl<T> DerefMut for DerefMutExample<T> { fn deref_mut<'a>(&'a mut self) -> &'a mut T { &mut self.value } } fn main() { let mut x = DerefMutExample { value: 'a' }; *x = 'b'; assert_eq!('b', *x); }use std::ops::{Deref, DerefMut}; struct DerefMutExample<T> { value: T } impl<T> Deref for DerefMutExample<T> { type Target = T; fn deref<'a>(&'a self) -> &'a T { &self.value } } impl<T> DerefMut for DerefMutExample<T> { fn deref_mut<'a>(&'a mut self) -> &'a mut T { &mut self.value } } fn main() { let mut x = DerefMutExample { value: 'a' }; *x = 'b'; assert_eq!('b', *x); }
Required Methods
Implementors
impl<'b, T> DerefMut for RefMut<'b, T> where T: ?Sized
impl<T> DerefMut for Box<T> where T: ?Sized
impl DerefMut for String
impl<T> DerefMut for Vec<T>
impl<T> DerefMut for AssertUnwindSafe<T>
impl<T> DerefMut for AssertRecoverSafe<T>
impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T>
impl<'rwlock, T: ?Sized> DerefMut for RwLockWriteGuard<'rwlock, T>