fuse3/path/
inode_generator.rs

1use slab::Slab;
2
3use crate::Inode;
4
5#[derive(Debug)]
6pub struct InodeGenerator {
7    slab: Slab<()>,
8}
9
10impl InodeGenerator {
11    pub fn new() -> Self {
12        let mut slab = Slab::new();
13        // drop 0 key
14        slab.insert(());
15
16        Self { slab }
17    }
18
19    pub fn allocate_inode(&mut self) -> Inode {
20        self.slab.insert(()) as _
21    }
22
23    pub fn release_inode(&mut self, inode: Inode) {
24        if self.slab.contains(inode as _) {
25            self.slab.remove(inode as _);
26        }
27    }
28}