miden_assembly_syntax/ast/procedure/
id.rs

1/// Represents the index of a procedure within a single module.
2#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3#[repr(transparent)]
4pub struct ProcedureIndex(u16);
5
6impl ProcedureIndex {
7    pub fn new(id: usize) -> Self {
8        Self(id.try_into().expect("invalid procedure index: too many procedures"))
9    }
10
11    pub const fn const_new(id: u16) -> Self {
12        Self(id)
13    }
14
15    #[inline(always)]
16    pub const fn as_usize(&self) -> usize {
17        self.0 as usize
18    }
19}
20
21impl core::fmt::Display for ProcedureIndex {
22    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23        write!(f, "{}", &self.as_usize())
24    }
25}