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// facade tests.
9//! A single configured filesystem limit.
10
11/// A provider-declared limit for one filesystem property.
12///
13/// # Examples
14///
15/// ```rust
16/// use qubit_fs::metadata::FileSystemLimit;
17///
18/// assert!(matches!(FileSystemLimit::Unknown, FileSystemLimit::Unknown));
19/// ```
20#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
21pub enum FileSystemLimit {
22    /// The provider cannot report a stable limit at construction time.
23    Unknown,
24    /// The limit dimension does not apply to this provider.
25    NotApplicable,
26    /// The provider imposes no finite limit at the `rs-fs` API layer.
27    Unbounded,
28    /// The inclusive maximum accepted value.
29    Maximum(
30        /// Inclusive maximum accepted value.
31        u64,
32    ),
33}
34
35impl FileSystemLimit {
36    /// Returns the finite inclusive maximum, when one exists.
37    #[inline]
38    #[must_use]
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    #[inline]
48    #[must_use]
49    pub const fn is_exceeded_by(self, actual: u64) -> bool {
50        matches!(self, Self::Maximum(maximum) if actual > maximum)
51    }
52}