pub struct SomeMut<'a, T>(/* private fields */);Expand description
A mutable reference to an Option that is guaranteed to always be Some.
Implementations§
Source§impl<'a, T> SomeMut<'a, T>
impl<'a, T> SomeMut<'a, T>
Sourcepub fn take(self) -> T
pub fn take(self) -> T
Take the value from this SomeMut, leaving a None in the original option.
§Examples
use some_mut::OptionExt;
let mut x = Some(vec![42, 10, 12]);
let mut y = 0;
let mut z = vec![];
for i in 0..5 {
if let Some(x) = x.some_mut() {
y += 2;
if y >= 4 {
z = x.take();
}
} else {
z.push(i)
}
}
assert!(x.is_none());
assert_eq!(y, 4);
assert_eq!(z, [42, 10, 12, 2, 3, 4])Sourcepub fn into_mut(self) -> &'a mut T
pub fn into_mut(self) -> &'a mut T
Unwrap this SomeMut into a normal mutable reference, with a lifetime tied to the original option.
Sourcepub fn into_option_mut(self) -> &'a mut Option<T>
pub fn into_option_mut(self) -> &'a mut Option<T>
Unwrap this SomeMut into a mutable reference to the original option.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for SomeMut<'a, T>
impl<'a, T> RefUnwindSafe for SomeMut<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for SomeMut<'a, T>where
T: Send,
impl<'a, T> Sync for SomeMut<'a, T>where
T: Sync,
impl<'a, T> Unpin for SomeMut<'a, T>
impl<'a, T> !UnwindSafe for SomeMut<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more