sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use crate::{Error, lib_enum};

lib_enum! {
    /// Represents the direction of the queued task operation.
    Direction: u8 {
        default: Write,
        error: Error,
        /// Queued write task.
        Write = 0,
        /// Queued read task.
        Read = 1,
    }
}

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

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

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

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