#![warn(missing_docs)]
use std::{error, fmt, str};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ParseModeError {}
impl fmt::Display for ParseModeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Error Parsing a CFD-16 Execution Mode.")
}
}
impl error::Error for ParseModeError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Mode {
User,
Kernel,
}
impl fmt::Display for Mode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Mode::User => write!(f, "User"),
Mode::Kernel => write!(f, "Kernel"),
}
}
}
impl str::FromStr for Mode {
type Err = ParseModeError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"user" => Ok(Mode::User),
"kernel" => Ok(Mode::Kernel),
_ => Err(Self::Err {}),
}
}
}
pub trait Codable
where
Self: Sized,
{
fn encode(&self) -> u16;
fn decode(value: u16, mode: Mode) -> Option<Self>;
}