use core::fmt;
use core::num::NonZeroU64;
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NodeId(NonZeroU64);
impl NodeId {
pub(crate) fn from_index(index: u64) -> Self {
let value = NonZeroU64::new(index).expect("node ids start at 1");
Self(value)
}
pub fn get(self) -> u64 {
self.0.get()
}
}
impl fmt::Debug for NodeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "NodeId({})", self.get())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ScopeId(NonZeroU64);
impl ScopeId {
pub(crate) fn from_index(index: u64) -> Self {
let value = NonZeroU64::new(index).expect("scope ids start at 1");
Self(value)
}
pub fn get(self) -> u64 {
self.0.get()
}
}
impl fmt::Debug for ScopeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ScopeId({})", self.get())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OutputKey(NonZeroU64);
impl OutputKey {
pub(crate) fn from_index(index: u64) -> Self {
let value = NonZeroU64::new(index).expect("output keys start at 1");
Self(value)
}
pub fn get(self) -> u64 {
self.0.get()
}
}
impl fmt::Debug for OutputKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "OutputKey({})", self.get())
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Revision(u64);
impl Revision {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
pub(crate) const fn next(self) -> Self {
Self(self.0 + 1)
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransactionId(u64);
impl TransactionId {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
pub(crate) const fn next(self) -> Self {
Self(self.0 + 1)
}
}