aboutsummaryrefslogtreecommitdiff
path: root/src/client/fs/ino.rs
blob: 0b7628ecf9daf881c6ba609bae25602cfef223b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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()
    }
}