sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
pub const MID_LEN: usize = 1;

/// Represents an 8-bit manufacturer ID.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ManufacturerId(u8);

impl ManufacturerId {
    /// Creates a new [ManufacturerId].
    pub const fn new() -> Self {
        Self(0)
    }

    /// Gets the bit value for the [ManufacturerId].
    pub const fn bits(&self) -> u8 {
        self.0
    }

    /// Converts a [`u8`] into a [ManufacturerId].
    pub const fn from_bits(val: u8) -> Self {
        Self(val)
    }
}

impl Default for ManufacturerId {
    fn default() -> Self {
        Self::new()
    }
}

impl From<u8> for ManufacturerId {
    fn from(val: u8) -> Self {
        Self::from_bits(val)
    }
}

impl From<ManufacturerId> for u8 {
    fn from(val: ManufacturerId) -> Self {
        val.bits()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_valid() {
        assert_eq!(ManufacturerId::new().bits(), 0);

        (0..u8::MAX).for_each(|id| {
            let exp_mid = ManufacturerId(id);

            assert_eq!(ManufacturerId::from_bits(id), exp_mid);
            assert_eq!(exp_mid.bits(), id);
        });
    }
}