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
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)