diff options
Diffstat (limited to 'src/client/fs/ino.rs')
-rw-r--r-- | src/client/fs/ino.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/client/fs/ino.rs b/src/client/fs/ino.rs new file mode 100644 index 0000000..0b7628e --- /dev/null +++ b/src/client/fs/ino.rs @@ -0,0 +1,51 @@ +use std::fmt::Display; + +const ROOT_INO: u64 = 1; + +#[derive(Clone, Debug, Eq, PartialEq, Hash, Copy)] +pub struct Ino(u64); + +impl Ino { + pub fn new() -> Self { + Self(ROOT_INO) + } + + pub fn next(&mut self) -> &Self { + self.0 += 1; + self + } + + pub fn prev(&mut self) { + self.0 -= 1; + } +} + +impl From<Ino> for u64 { + fn from(ino: Ino) -> Self { + ino.0 + } +} + +impl From<u64> for Ino { + fn from(ino: u64) -> Self { + Self(ino) + } +} + +impl From<u32> for Ino { + fn from(ino: u32) -> Self { + Self(u64::from(ino)) + } +} + +impl Display for Ino { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + +impl Default for Ino { + fn default() -> Self { + Self::new() + } +} |