commit 34324db9764d4ee3412a57ac969d7cb8e814cc4c Author: Dominik Werder Date: Thu Nov 7 21:21:58 2024 +0100 Factored into separate crate diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b72444 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/Cargo.lock +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1362c3f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "daqbuf-series" +version = "0.0.2" +authors = ["Dominik Werder "] +edition = "2021" + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +#log = { path = "../log" } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..e925768 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +pub mod series; + +pub use series::ChannelStatusSeriesId; +pub use series::SeriesId; + +// use log::*; + +// pub fn log_test() { +// info!("log-test"); +// warn!("log-test"); +// error!("log-test"); +// debug!("log-test"); +// trace!("log-test"); +// } diff --git a/src/series.rs b/src/series.rs new file mode 100644 index 0000000..5befc30 --- /dev/null +++ b/src/series.rs @@ -0,0 +1,59 @@ +use core::fmt; +use serde::Deserialize; +use serde::Serialize; + +#[derive(Clone, Debug)] +pub enum Existence { + Created(T), + Existing(T), +} + +impl Existence { + pub fn into_inner(self) -> T { + use Existence::*; + match self { + Created(x) => x, + Existing(x) => x, + } + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +pub struct SeriesId(u64); + +impl SeriesId { + pub fn new(id: u64) -> Self { + Self(id) + } + + pub fn id(&self) -> u64 { + self.0 + } + + pub fn to_i64(&self) -> i64 { + self.0 as i64 + } +} + +impl fmt::Display for SeriesId { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "SeriesId {{ {:20} }}", self.0) + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +pub struct ChannelStatusSeriesId(u64); + +impl ChannelStatusSeriesId { + pub fn new(id: u64) -> Self { + Self(id) + } + + pub fn id(&self) -> u64 { + self.0 + } + + pub fn to_i64(&self) -> i64 { + self.0 as i64 + } +}