acir/native_types/
witness.rs

1use serde::{Deserialize, Serialize};
2
3/// An index that represents the position a witness value will take
4#[derive(
5    Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize,
6)]
7#[cfg_attr(feature = "arb", derive(proptest_derive::Arbitrary))]
8pub struct Witness(pub u32);
9
10impl Witness {
11    pub fn new(witness_index: u32) -> Witness {
12        Witness(witness_index)
13    }
14    pub fn witness_index(&self) -> u32 {
15        self.0
16    }
17    pub fn as_usize(&self) -> usize {
18        // This is safe as long as the architecture is 32bits minimum
19        self.0 as usize
20    }
21}
22
23impl From<u32> for Witness {
24    fn from(value: u32) -> Self {
25        Self(value)
26    }
27}
28
29impl std::fmt::Display for Witness {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        write!(f, "w{}", self.0)
32    }
33}