Skip to main content

qubit_fs/metadata/
file_system_limit.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! A single configured filesystem limit.
9
10/// A provider-declared limit for one filesystem property.
11///
12/// # Examples
13///
14/// ```rust
15/// use qubit_fs::metadata::FileSystemLimit;
16///
17/// let limit = FileSystemLimit::Maximum(4096);
18/// assert_eq!(limit.maximum(), Some(4096));
19/// assert!(!limit.is_exceeded_by(4096));
20/// ```
21#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
22pub enum FileSystemLimit {
23    /// The provider cannot report a stable limit at construction time.
24    Unknown,
25    /// The limit dimension does not apply to this provider.
26    NotApplicable,
27    /// The provider imposes no finite limit at the `rs-fs` API layer.
28    Unbounded,
29    /// The inclusive maximum accepted value.
30    Maximum(
31        /// Inclusive maximum accepted value.
32        u64,
33    ),
34}
35
36impl FileSystemLimit {
37    /// Returns the finite inclusive maximum, when one exists.
38    #[inline]
39    pub const fn maximum(self) -> Option<u64> {
40        match self {
41            Self::Maximum(maximum) => Some(maximum),
42            Self::Unknown | Self::NotApplicable | Self::Unbounded => None,
43        }
44    }
45
46    /// Returns whether `actual` exceeds a declared finite maximum.
47    ///
48    /// # Parameters
49    /// - `actual`: Value to compare with the inclusive maximum, if present.
50    #[inline]
51    #[must_use]
52    pub const fn is_exceeded_by(self, actual: u64) -> bool {
53        matches!(self, Self::Maximum(maximum) if actual > maximum)
54    }
55}