sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use crate::lib_enum;
use crate::result::Error;

lib_enum! {
    /// Mask/write mode.
    Mask: u8 {
        default: Disabled,
        error: Error,
        /// Mask is disabled, enabling the `len` field for access length.
        Disabled = 0,
        /// Mask is enabled, fixing the `len` field for access length to 1-byte.
        Enabled = 1,
    }
}

impl Mask {
    /// Converts a [`bool`] into a [Mask].
    pub const fn from_bool(val: bool) -> Self {
        match val {
            false => Self::Disabled,
            true => Self::Enabled,
        }
    }

    /// Converts a [Mask] into a [`bool`].
    pub const fn into_bool(self) -> bool {
        (self as u8) != 0
    }
}

impl From<bool> for Mask {
    fn from(val: bool) -> Self {
        Self::from_bool(val)
    }
}

impl From<Mask> for bool {
    fn from(val: Mask) -> Self {
        val.into_bool()
    }
}