Factored into separate crate
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/Cargo.lock
|
||||
/target
|
||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "daqbuf-series"
|
||||
version = "0.0.2"
|
||||
authors = ["Dominik Werder <dominik.werder@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
#log = { path = "../log" }
|
||||
14
src/lib.rs
Normal file
14
src/lib.rs
Normal file
@@ -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");
|
||||
// }
|
||||
59
src/series.rs
Normal file
59
src/series.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use core::fmt;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Existence<T> {
|
||||
Created(T),
|
||||
Existing(T),
|
||||
}
|
||||
|
||||
impl<T> Existence<T> {
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user