Skip to content

Commit f6d9453

Browse files
committed
Implement identifiers for clock and link.
1 parent 56130fe commit f6d9453

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

statime-base/src/identifiers.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use core::sync::atomic::AtomicUsize;
2+
3+
/// Unique identifier for a clock
4+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
5+
pub struct ClockId(usize);
6+
7+
impl ClockId {
8+
/// Get a new identifier for a clock.
9+
#[expect(
10+
clippy::new_without_default,
11+
reason = "The new value is non-trivial and non-constant, therefore not fitting for default."
12+
)]
13+
pub fn new() -> ClockId {
14+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
15+
ClockId(COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
16+
}
17+
}
18+
19+
/// Unique identifier for a clock
20+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
21+
pub struct LinkId(usize);
22+
23+
impl LinkId {
24+
/// Get a new identifier for a clock.
25+
#[expect(
26+
clippy::new_without_default,
27+
reason = "The new value is non-trivial and non-constant, therefore not fitting for default."
28+
)]
29+
pub fn new() -> LinkId {
30+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
31+
LinkId(COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
32+
}
33+
}

statime-base/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Base types and traits for time management.
22
#![no_std]
33

4+
mod identifiers;
45
mod time_types;
6+
7+
pub use identifiers::*;
58
pub use time_types::*;
69

710
#[cfg(feature = "std")]

0 commit comments

Comments
 (0)