pub struct Mc<T>(/* private fields */);
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§
Source§impl<T, R> AddAssign<R> for Mc<T>where
T: AddAssign<R>,
impl<T, R> AddAssign<R> for Mc<T>where
T: AddAssign<R>,
Source§fn add_assign(&mut self, rhs: R)
fn add_assign(&mut self, rhs: R)
Performs the
+=
operation. Read moreSource§impl<T, R> BitAndAssign<R> for Mc<T>where
T: BitAndAssign<R>,
impl<T, R> BitAndAssign<R> for Mc<T>where
T: BitAndAssign<R>,
Source§fn bitand_assign(&mut self, rhs: R)
fn bitand_assign(&mut self, rhs: R)
Performs the
&=
operation. Read moreSource§impl<T, R> BitOrAssign<R> for Mc<T>where
T: BitOrAssign<R>,
impl<T, R> BitOrAssign<R> for Mc<T>where
T: BitOrAssign<R>,
Source§fn bitor_assign(&mut self, rhs: R)
fn bitor_assign(&mut self, rhs: R)
Performs the
|=
operation. Read moreSource§impl<T, R> BitXorAssign<R> for Mc<T>where
T: BitXorAssign<R>,
impl<T, R> BitXorAssign<R> for Mc<T>where
T: BitXorAssign<R>,
Source§fn bitxor_assign(&mut self, rhs: R)
fn bitxor_assign(&mut self, rhs: R)
Performs the
^=
operation. Read moreSource§impl<T, R> DivAssign<R> for Mc<T>where
T: DivAssign<R>,
impl<T, R> DivAssign<R> for Mc<T>where
T: DivAssign<R>,
Source§fn div_assign(&mut self, rhs: R)
fn div_assign(&mut self, rhs: R)
Performs the
/=
operation. Read moreSource§impl<T, R> MulAssign<R> for Mc<T>where
T: MulAssign<R>,
impl<T, R> MulAssign<R> for Mc<T>where
T: MulAssign<R>,
Source§fn mul_assign(&mut self, rhs: R)
fn mul_assign(&mut self, rhs: R)
Performs the
*=
operation. Read moreSource§impl<T> Ord for Mc<T>
impl<T> Ord for Mc<T>
Source§impl<T, R> PartialOrd<R> for Mc<T>where
T: PartialOrd<R> + Clone,
impl<T, R> PartialOrd<R> for Mc<T>where
T: PartialOrd<R> + Clone,
Source§impl<T, R> RemAssign<R> for Mc<T>where
T: RemAssign<R>,
impl<T, R> RemAssign<R> for Mc<T>where
T: RemAssign<R>,
Source§fn rem_assign(&mut self, rhs: R)
fn rem_assign(&mut self, rhs: R)
Performs the
%=
operation. Read moreSource§impl<T> ShlAssign<usize> for Mc<T>
impl<T> ShlAssign<usize> for Mc<T>
Source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
Performs the
<<=
operation. Read moreSource§impl<T> ShrAssign<usize> for Mc<T>
impl<T> ShrAssign<usize> for Mc<T>
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
Performs the
>>=
operation. Read moreSource§impl<T, R> SubAssign<R> for Mc<T>where
T: SubAssign<R>,
impl<T, R> SubAssign<R> for Mc<T>where
T: SubAssign<R>,
Source§fn sub_assign(&mut self, rhs: R)
fn sub_assign(&mut self, rhs: R)
Performs the
-=
operation. Read moreimpl<T> Eq for Mc<T>
Auto Trait Implementations§
impl<T> Freeze for Mc<T>
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