elfo_core/
addr.rs

1use std::fmt;
2
3// TODO: improve `Debug` and `Display` instances.
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub struct Addr(usize);
7
8impl fmt::Display for Addr {
9    #[inline]
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        // TODO: print a version.
12        write!(f, "{}v0", self.0)
13    }
14}
15
16impl Addr {
17    pub const NULL: Addr = Addr(usize::MAX);
18
19    #[cfg(feature = "test-util")]
20    pub fn from_bits(bits: usize) -> Self {
21        Addr(bits)
22    }
23
24    #[cfg(not(feature = "test-util"))]
25    pub(crate) fn from_bits(bits: usize) -> Self {
26        Addr(bits)
27    }
28
29    pub(crate) fn into_bits(self) -> usize {
30        self.0
31    }
32}