Skip to main content

feldera_storage/
file.rs

1use std::sync::atomic::{AtomicU64, Ordering};
2
3/// A unique identifier for a [crate::FileReader] or [crate::FileWriter].
4///
5/// The buffer cache uses this ID for indexing.
6#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct FileId(u64);
8
9impl FileId {
10    /// Creates a fresh unique identifier.
11    #[allow(clippy::new_without_default)]
12    pub fn new() -> Self {
13        static NEXT_FILE_ID: AtomicU64 = AtomicU64::new(0);
14        Self(NEXT_FILE_ID.fetch_add(1, Ordering::Relaxed))
15    }
16
17    pub fn after(&self) -> Self {
18        Self(self.0 + 1)
19    }
20}