use std::{fmt::Display, str::FromStr};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Section {
Accumulate,
Assurances,
Authorizations,
Codec,
Disputes,
History,
Preimages,
Pvm,
Reports,
Safrole,
Statistics,
Shuffle,
Trace(Trace),
Trie,
}
impl Section {
pub fn all() -> [Section; 16] {
[
Section::Accumulate,
Section::Assurances,
Section::Authorizations,
Section::Codec,
Section::Pvm,
Section::Safrole,
Section::Statistics,
Section::Disputes,
Section::History,
Section::Preimages,
Section::Reports,
Section::Shuffle,
Section::Trie,
Section::Trace(Trace::Fallback),
Section::Trace(Trace::Safrole),
Section::Trace(Trace::ReportsL0),
]
}
}
impl FromStr for Section {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"accumulate" => Ok(Section::Accumulate),
"assurances" => Ok(Section::Assurances),
"codec" => Ok(Section::Codec),
"pvm" => Ok(Section::Pvm),
"safrole" => Ok(Section::Safrole),
"statistics" => Ok(Section::Statistics),
"authorizations" => Ok(Section::Authorizations),
"disputes" => Ok(Section::Disputes),
"history" => Ok(Section::History),
"preimages" => Ok(Section::Preimages),
"reports" => Ok(Section::Reports),
"shuffle" => Ok(Section::Shuffle),
"traces/fallback" => Ok(Section::Trace(Trace::Fallback)),
"traces/safrole" => Ok(Section::Trace(Trace::Safrole)),
"traces/reports-l0" => Ok(Section::Trace(Trace::ReportsL0)),
"trie" => Ok(Section::Trie),
_ => Err(anyhow::anyhow!("Invalid section {s}")),
}
}
}
impl AsRef<str> for Section {
fn as_ref(&self) -> &str {
match self {
Section::Accumulate => "accumulate",
Section::Assurances => "assurances",
Section::Codec => "codec/data",
Section::Pvm => "pvm/programs",
Section::Safrole => "safrole",
Section::Statistics => "statistics",
Section::Authorizations => "authorizations",
Section::Disputes => "disputes",
Section::History => "history/data",
Section::Preimages => "preimages/data",
Section::Reports => "reports",
Section::Shuffle => "shuffle",
Section::Trace(trace) => match trace {
Trace::Fallback => "traces/fallback",
Trace::Safrole => "traces/safrole",
Trace::ReportsL0 => "traces/reports-l0",
},
Section::Trie => "trie",
}
}
}
impl Display for Section {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_ref())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Trace {
Fallback,
Safrole,
ReportsL0,
}
impl AsRef<str> for Trace {
fn as_ref(&self) -> &str {
match self {
Trace::Fallback => "fallback",
Trace::Safrole => "safrole",
Trace::ReportsL0 => "reports-l0",
}
}
}