mode.rs: Implement more traits for use in frontend
This commit is contained in:
parent
59ba8ac20b
commit
04736f1153
@ -28,12 +28,37 @@ impl FromStr for Mode {
|
|||||||
|
|
||||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||||
match s.to_lowercase().as_str() {
|
match s.to_lowercase().as_str() {
|
||||||
"chip8" | "chip-8" => Ok(Mode::Chip8),
|
"chip" | "chip8" | "chip-8" => Ok(Mode::Chip8),
|
||||||
"schip" | "superchip" => Ok(Mode::SChip),
|
"s" | "schip" | "superchip" | "super chip" => Ok(Mode::SChip),
|
||||||
"xo-chip" | "xochip" => Ok(Mode::XOChip),
|
"xo" | "xochip" | "xo-chip" => Ok(Mode::XOChip),
|
||||||
_ => Err(Error::InvalidMode {
|
_ => Err(Error::InvalidMode { mode: s.into() }),
|
||||||
mode: s.to_string(),
|
}
|
||||||
}),
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for Mode {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Mode::Chip8 => "Chip-8",
|
||||||
|
Mode::SChip => "Super Chip",
|
||||||
|
Mode::XOChip => "XO-Chip",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for Mode {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
self.as_ref().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<usize> for Mode {
|
||||||
|
fn from(value: usize) -> Self {
|
||||||
|
match value {
|
||||||
|
0 => Self::Chip8,
|
||||||
|
1 => Self::SChip,
|
||||||
|
2 => Self::XOChip,
|
||||||
|
_ => Self::Chip8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user