use bitflags::bitflags;
use core::fmt;
bitflags! {
pub struct Oscillator: u8 {
const COMMAND = 0b0010_0000;
const ON = 0b0000_0001;
const OFF = 0b0000_0000;
}
}
impl Default for Oscillator {
fn default() -> Oscillator {
Oscillator::OFF
}
}
impl fmt::Display for Oscillator {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Oscillator::COMMAND => write!(f, "Oscillator::COMMAND"),
Oscillator::ON => write!(f, "Oscillator::ON"),
Oscillator::OFF => write!(f, "Oscillator::OFF"),
_ => write!(f, "Oscillator::{:#10b}", self.bits()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default() {
assert_eq!(
Oscillator::OFF,
Oscillator::default(),
"Oscillator default is OFF"
);
}
}