rune/parse/
id.rs

1use core::fmt;
2use core::num::NonZeroU32;
3
4use crate as rune;
5use crate::alloc::prelude::*;
6
7/// A non-zero identifier which definitely contains a value.
8#[derive(TryClone, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[try_clone(copy)]
10#[repr(transparent)]
11pub struct NonZeroId(#[try_clone(copy)] NonZeroU32);
12
13impl fmt::Display for NonZeroId {
14    #[inline]
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        self.0.fmt(f)
17    }
18}
19
20impl fmt::Debug for NonZeroId {
21    #[inline]
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        self.0.fmt(f)
24    }
25}
26
27impl From<NonZeroU32> for NonZeroId {
28    fn from(value: NonZeroU32) -> Self {
29        Self(value)
30    }
31}