1use std::{
2 num::NonZeroU64,
3 ops::AddAssign,
4};
5
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash, PartialOrd, Ord)]
8pub struct ScopeId(pub NonZeroU64);
9
10impl ScopeId {
11 pub const ROOT: ScopeId = ScopeId(NonZeroU64::MIN);
12}
13
14impl From<u64> for ScopeId {
15 fn from(value: u64) -> Self {
16 Self(NonZeroU64::new(value).unwrap())
17 }
18}
19
20impl AddAssign<u64> for ScopeId {
21 fn add_assign(&mut self, other: u64) {
22 self.0 = self.0.saturating_add(other);
23 }
24}