mister_fpga/config/
bootcore.rs

1use serde_with::DeserializeFromStr;
2use std::convert::Infallible;
3use std::fmt::{Display, Formatter};
4use std::str::FromStr;
5
6#[derive(DeserializeFromStr, Debug, Default, Clone, PartialEq, Eq)]
7pub enum BootCoreConfig {
8    #[default]
9    None,
10    LastCore,
11    ExactLastCore,
12    CoreName(String),
13}
14
15impl BootCoreConfig {
16    pub fn is_none(&self) -> bool {
17        self == &BootCoreConfig::None
18    }
19    pub fn is_last_core(&self) -> bool {
20        matches!(
21            self,
22            BootCoreConfig::LastCore | BootCoreConfig::ExactLastCore
23        )
24    }
25}
26
27impl Display for BootCoreConfig {
28    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29        match self {
30            BootCoreConfig::None => write!(f, ""),
31            BootCoreConfig::LastCore => write!(f, "lastcore"),
32            BootCoreConfig::ExactLastCore => write!(f, "exactlastcore"),
33            BootCoreConfig::CoreName(name) => write!(f, "{}", name),
34        }
35    }
36}
37
38impl FromStr for BootCoreConfig {
39    type Err = Infallible;
40
41    fn from_str(s: &str) -> Result<Self, Self::Err> {
42        match s.to_lowercase().as_str() {
43            "" => Ok(BootCoreConfig::None),
44            "lastcore" => Ok(BootCoreConfig::LastCore),
45            "exactlastcore" => Ok(BootCoreConfig::ExactLastCore),
46            _ => Ok(BootCoreConfig::CoreName(s.into())),
47        }
48    }
49}