Add helpers

This commit is contained in:
Dominik Werder
2025-03-13 10:31:38 +01:00
parent c673dd890f
commit 5c2300d83c

View File

@@ -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<Self, Error> {
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<DtMs> for PrebinnedPartitioning {