rune/parse/
id.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use core::fmt;
use core::num::NonZeroU32;

use crate as rune;
use crate::alloc::prelude::*;

/// A non-zero identifier which definitely contains a value.
#[derive(TryClone, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[try_clone(copy)]
#[repr(transparent)]
pub struct NonZeroId(#[try_clone(copy)] NonZeroU32);

impl fmt::Display for NonZeroId {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl fmt::Debug for NonZeroId {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl From<NonZeroU32> for NonZeroId {
    fn from(value: NonZeroU32) -> Self {
        Self(value)
    }
}