acir/circuit/opcodes/
function_id.rs

1use msgpack_tagged::MsgpackTagged;
2use serde::{Deserialize, Serialize};
3
4/// Id for the function being called.
5/// Indexes into the table of ACIR function's specified in a [program][crate::circuit::Program]
6#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
7#[derive(Serialize, Deserialize, MsgpackTagged)]
8#[cfg_attr(feature = "arb", derive(proptest_derive::Arbitrary))]
9#[serde(transparent)]
10pub struct AcirFunctionId(u32);
11
12impl AcirFunctionId {
13    /// Creates an `AcirFunctionId` indexing into a [program][crate::circuit::Program]'s
14    /// table of ACIR functions by its raw index.
15    pub fn new(id: u32) -> Self {
16        AcirFunctionId(id)
17    }
18
19    pub fn as_u32(&self) -> u32 {
20        self.0
21    }
22
23    pub fn as_usize(&self) -> usize {
24        self.0 as usize
25    }
26}
27
28impl std::fmt::Display for AcirFunctionId {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        write!(f, "{}", self.0)
31    }
32}