use crate::lib_bitfield;
use crate::result::Result;
use super::{ExtCsd, ExtCsdIndex};
mod info;
pub use info::*;
lib_bitfield! {
PreEolInfo: u8,
mask: 0xff,
default: 1,
{
pre_eol_info: LifetimeInformation, 7, 0;
}
}
impl ExtCsd {
pub const fn pre_eol_info(&self) -> Result<PreEolInfo> {
PreEolInfo::try_from_inner(self.0[ExtCsdIndex::PreEolInfo.into_inner()])
}
pub(crate) fn set_pre_eol_info(&mut self, val: PreEolInfo) {
self.0[ExtCsdIndex::PreEolInfo.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_pre_eol_info() {
let mut ext_csd = ExtCsd::new();
ext_csd.set_pre_eol_info(PreEolInfo::new());
assert_eq!(ext_csd.pre_eol_info(), Ok(PreEolInfo::new()));
(0..=u8::MAX).for_each(|raw_info| {
ext_csd.set_pre_eol_info(PreEolInfo(raw_info));
match PreEolInfo::try_from_inner(raw_info) {
Ok(info) => assert_eq!(ext_csd.pre_eol_info(), Ok(info)),
Err(err) => assert_eq!(ext_csd.pre_eol_info(), Err(err)),
}
});
}
}