diff --git a/src/msp.rs b/src/msp.rs index a27f77f..6a8eac2 100644 --- a/src/msp.rs +++ b/src/msp.rs @@ -7,9 +7,13 @@ autoerr::create_error_v1!( enum variants { PrebinnedPartitioningInvalid, BadDv1(u32), + BadPbp(u32), }, ); +#[derive(Debug, Clone)] +pub struct MspU32(pub u32); + #[derive(Debug, Clone)] pub enum PrebinnedPartitioning { Sec1, @@ -114,6 +118,19 @@ impl PrebinnedPartitioning { Day1 => 6, } } + + pub fn from_db_ix(x: u32) -> Result { + use PrebinnedPartitioning::*; + match x { + 1 => Ok(Sec1), + 2 => Ok(Sec10), + 3 => Ok(Min1), + 4 => Ok(Min10), + 5 => Ok(Hour1), + 6 => Ok(Day1), + _ => Err(Error::BadPbp(x)), + } + } } impl TryFrom for PrebinnedPartitioning {