Struct Mc

Source
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>

Source

pub fn new(t: T) -> Mc<T>

Creates a new Mc from a value.

§Example
use mutable_constant::Mc;
 
let mc = Mc::new(42);
Source

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> Add<R> for Mc<T>
where T: Add<R> + Clone,

Source§

type Output = <T as Add<R>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: R) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, R> AddAssign<R> for Mc<T>
where T: AddAssign<R>,

Source§

fn add_assign(&mut self, rhs: R)

Performs the += operation. Read more
Source§

impl<T> AsMut<T> for Mc<T>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsRef<T> for Mc<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, R> BitAnd<R> for Mc<T>
where T: BitAnd<R> + Clone,

Source§

type Output = <T as BitAnd<R>>::Output

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: R) -> Self::Output

Performs the & operation. Read more
Source§

impl<T, R> BitAndAssign<R> for Mc<T>
where T: BitAndAssign<R>,

Source§

fn bitand_assign(&mut self, rhs: R)

Performs the &= operation. Read more
Source§

impl<T, R> BitOr<R> for Mc<T>
where T: BitOr<R> + Clone,

Source§

type Output = <T as BitOr<R>>::Output

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: R) -> Self::Output

Performs the | operation. Read more
Source§

impl<T, R> BitOrAssign<R> for Mc<T>
where T: BitOrAssign<R>,

Source§

fn bitor_assign(&mut self, rhs: R)

Performs the |= operation. Read more
Source§

impl<T, R> BitXor<R> for Mc<T>
where T: BitXor<R> + Clone,

Source§

type Output = <T as BitXor<R>>::Output

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: R) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T, R> BitXorAssign<R> for Mc<T>
where T: BitXorAssign<R>,

Source§

fn bitxor_assign(&mut self, rhs: R)

Performs the ^= operation. Read more
Source§

impl<T> Clone for Mc<T>
where T: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Mc<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for Mc<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for Mc<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Display for Mc<T>
where T: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, R> Div<R> for Mc<T>
where T: Div<R> + Clone,

Source§

type Output = <T as Div<R>>::Output

The resulting type after applying the / operator.
Source§

fn div(self, rhs: R) -> Self::Output

Performs the / operation. Read more
Source§

impl<T, R> DivAssign<R> for Mc<T>
where T: DivAssign<R>,

Source§

fn div_assign(&mut self, rhs: R)

Performs the /= operation. Read more
Source§

impl<T> Drop for Mc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Hash for Mc<T>
where T: Hash + Clone,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, R> Mul<R> for Mc<T>
where T: Mul<R> + Clone,

Source§

type Output = <T as Mul<R>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: R) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, R> MulAssign<R> for Mc<T>
where T: MulAssign<R>,

Source§

fn mul_assign(&mut self, rhs: R)

Performs the *= operation. Read more
Source§

impl<T> Neg for Mc<T>
where T: Neg + Clone,

Source§

type Output = <T as Neg>::Output

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T> Not for Mc<T>
where T: Not + Clone,

Source§

type Output = <T as Not>::Output

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<T> Ord for Mc<T>
where T: Ord + Clone + PartialOrd<Mc<T>>,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T, R> PartialEq<R> for Mc<T>
where T: PartialEq<R> + Clone,

Source§

fn eq(&self, other: &R) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, R> PartialOrd<R> for Mc<T>
where T: PartialOrd<R> + Clone,

Source§

fn partial_cmp(&self, other: &R) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, R> Rem<R> for Mc<T>
where T: Rem<R> + Clone,

Source§

type Output = <T as Rem<R>>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: R) -> Self::Output

Performs the % operation. Read more
Source§

impl<T, R> RemAssign<R> for Mc<T>
where T: RemAssign<R>,

Source§

fn rem_assign(&mut self, rhs: R)

Performs the %= operation. Read more
Source§

impl<T> Shl<usize> for Mc<T>
where T: Shl<usize> + Clone,

Source§

type Output = <T as Shl<usize>>::Output

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: usize) -> Self::Output

Performs the << operation. Read more
Source§

impl<T> ShlAssign<usize> for Mc<T>
where T: ShlAssign<usize>,

Source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
Source§

impl<T> Shr<usize> for Mc<T>
where T: Shr<usize> + Clone,

Source§

type Output = <T as Shr<usize>>::Output

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: usize) -> Self::Output

Performs the >> operation. Read more
Source§

impl<T> ShrAssign<usize> for Mc<T>
where T: ShrAssign<usize>,

Source§

fn shr_assign(&mut self, rhs: usize)

Performs the >>= operation. Read more
Source§

impl<T, R> Sub<R> for Mc<T>
where T: Sub<R> + Clone,

Source§

type Output = <T as Sub<R>>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: R) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, R> SubAssign<R> for Mc<T>
where T: SubAssign<R>,

Source§

fn sub_assign(&mut self, rhs: R)

Performs the -= operation. Read more
Source§

impl<T> Eq for Mc<T>
where T: Eq + Clone + PartialEq<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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.