mod types;
pub use types::*;
macro_rules! impl_string_id {
($name:ident) => {
impl $name {
pub fn new(value: impl Into<String>) -> Self {
Self(value.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl From<String> for $name {
fn from(value: String) -> Self {
Self(value)
}
}
impl From<&str> for $name {
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}
};
}
impl_string_id!(RunId);
impl_string_id!(ThreadId);
impl_string_id!(CallId);
impl_string_id!(EventId);
impl_string_id!(ComponentId);
impl_string_id!(GraphId);
impl_string_id!(NodeId);
impl_string_id!(TaskId);
impl_string_id!(SessionId);
impl_string_id!(CellId);
impl_string_id!(CheckpointId);
impl_string_id!(InterruptId);
use std::sync::atomic::{AtomicU64, Ordering};
static ID_SEQ: AtomicU64 = AtomicU64::new(0);
pub fn next_seq() -> u64 {
ID_SEQ.fetch_add(1, Ordering::Relaxed)
}
pub fn new_session_id() -> SessionId {
SessionId(format!("session-{}", next_seq()))
}
pub fn new_cell_id() -> CellId {
CellId(format!("cell-{}", next_seq()))
}
pub fn new_call_id() -> CallId {
CallId(format!("call-{}", next_seq()))
}
#[cfg(test)]
mod test;