Struct mutable_constant::Mc
source · pub struct Mc<T>(_);
Expand description
A smart pointer that allows mutation on immutable values.
This uses a *mut T
internally, so most internal operations
are unsafe. However, thanks to Rust’s borrowing guarantees,
many of these operations are safe when used publicly. The
only operation that is not safe is as_defiant_mut
, which
creates a mutable reference in defiance of Rust’s rules.
Implementations§
source§impl<T> Mc<T>
impl<T> Mc<T>
sourcepub unsafe fn as_defiant_mut(&self) -> &mut T
pub unsafe fn as_defiant_mut(&self) -> &mut T
Gets a mutable reference to the inner value.
Safety
This is unsafe because the mutable reference does
not obey the borrow checker. For example, a mutable
reference to a Mc
can be created while there is
an immutable reference to the same Mc
. If you do
not need this specific behavior, use as_mut
instead.
Example
use mutable_constant::Mc;
let mut mc = Mc::new(42);
unsafe {
*mc.as_defiant_mut() = 43;
}
Trait Implementations§
Auto Trait Implementations§
impl<T> RefUnwindSafe for Mc<T>where T: RefUnwindSafe,
impl<T> !Send for Mc<T>
impl<T> !Sync for Mc<T>
impl<T> Unpin for Mc<T>
impl<T> UnwindSafe for Mc<T>where T: RefUnwindSafe,
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