rbe/
component.rs

1use core::hash::Hash;
2use serde::{Deserialize, Serialize};
3use std::fmt::Debug;
4use std::fmt::Display;
5
6/// A wrapper around a usize to represent a component in the RBE table.
7/// This is used to identify components in the RBE table and is used as a key in the
8/// `RbeTable` struct.
9#[derive(PartialEq, Eq, Hash, Default, Serialize, Deserialize, Clone, Copy)]
10pub struct Component(usize);
11
12impl Component {
13    pub fn new() -> Component {
14        Component(0)
15    }
16
17    pub fn from(n: usize) -> Component {
18        Component(n)
19    }
20}
21
22impl Display for Component {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        write!(f, "C{}", self.0)
25    }
26}
27
28impl Debug for Component {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        write!(f, "C{}", self.0)
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn test_component_creation() {
40        let c1: Component = Component::new();
41        assert_eq!(c1.0, 0)
42    }
43}