haloumi_core/slot/
output.rs

1//! Types related to circuit outputs.
2
3use std::{fmt, ops::Deref};
4
5/// An identifier that backends use to identify an output in the circuit.
6#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub struct OutputId(usize);
8
9impl From<usize> for OutputId {
10    fn from(value: usize) -> Self {
11        Self(value)
12    }
13}
14
15impl OutputId {
16    /// Offsets the field number by the given amount.
17    pub fn offset_by(self, offset: usize) -> Self {
18        Self(self.0 + offset)
19    }
20}
21
22impl Deref for OutputId {
23    type Target = usize;
24
25    fn deref(&self) -> &Self::Target {
26        &self.0
27    }
28}
29
30impl fmt::Display for OutputId {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        write!(f, "{}", self.0)
33    }
34}
35
36impl fmt::Debug for OutputId {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        write!(f, "field{}", self.0)
39    }
40}