pub enum Mutability {
Mutable,
Immutable,
}Variants§
Implementations§
Source§impl Mutability
impl Mutability
pub fn to_syn(&self) -> Option<Mut>
pub fn from_syn(t: &Option<Mut>) -> Self
Sourcepub fn is_mutable(&self) -> bool
pub fn is_mutable(&self) -> bool
Returns true if &self is the mutable variant, otherwise false.
Sourcepub fn is_immutable(&self) -> bool
pub fn is_immutable(&self) -> bool
Returns true if &self is the immutable variant, otherwise false.
Sourcepub fn if_mut_else<T>(&self, if_mut: T, if_immut: T) -> T
pub fn if_mut_else<T>(&self, if_mut: T, if_immut: T) -> T
Shorthand ternary operator for choosing a value based on whether
a Mutability is mutable or immutable.
The following pattern (with very slight variations) shows up often in code gen:
if mutability.is_mutable() {
""
} else {
"const "
}This is particularly annoying in write!(...) statements, where cargo fmt
expands it to take up 5 lines.
This method offers a 1-line alternative:
mutability.if_mut_else("", "const ")For cases where lazy evaluation is desired, consider using a conditional
or a match statement.
Trait Implementations§
Source§impl Clone for Mutability
impl Clone for Mutability
Source§fn clone(&self) -> Mutability
fn clone(&self) -> Mutability
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Mutability
impl Debug for Mutability
Source§impl<'de> Deserialize<'de> for Mutability
impl<'de> Deserialize<'de> for Mutability
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Hash for Mutability
impl Hash for Mutability
Source§impl PartialEq for Mutability
impl PartialEq for Mutability
Source§impl Serialize for Mutability
impl Serialize for Mutability
impl Copy for Mutability
impl Eq for Mutability
impl StructuralPartialEq for Mutability
Auto Trait Implementations§
impl Freeze for Mutability
impl RefUnwindSafe for Mutability
impl Send for Mutability
impl Sync for Mutability
impl Unpin for Mutability
impl UnwindSafe for Mutability
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 1 byte
Size for each variant:
Mutable: 0 bytesImmutable: 0 bytes