qubit-fs 0.3.3

Provider-neutral synchronous and asynchronous filesystem abstraction for Rust
Documentation
// =============================================================================
//    Copyright (c) 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================
//! A single configured filesystem limit.

/// A provider-declared limit for one filesystem property.
///
/// # Examples
///
/// ```rust
/// use qubit_fs::metadata::FileSystemLimit;
///
/// let limit = FileSystemLimit::Maximum(4096);
/// assert_eq!(limit.maximum(), Some(4096));
/// assert!(!limit.is_exceeded_by(4096));
/// ```
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum FileSystemLimit {
    /// The provider cannot report a stable limit at construction time.
    Unknown,
    /// The limit dimension does not apply to this provider.
    NotApplicable,
    /// The provider imposes no finite limit at the `rs-fs` API layer.
    Unbounded,
    /// The inclusive maximum accepted value.
    Maximum(
        /// Inclusive maximum accepted value.
        u64,
    ),
}

impl FileSystemLimit {
    /// Returns the finite inclusive maximum, when one exists.
    #[inline]
    pub const fn maximum(self) -> Option<u64> {
        match self {
            Self::Maximum(maximum) => Some(maximum),
            Self::Unknown | Self::NotApplicable | Self::Unbounded => None,
        }
    }

    /// Returns whether `actual` exceeds a declared finite maximum.
    ///
    /// # Parameters
    /// - `actual`: Value to compare with the inclusive maximum, if present.
    #[inline]
    #[must_use]
    pub const fn is_exceeded_by(self, actual: u64) -> bool {
        matches!(self, Self::Maximum(maximum) if actual > maximum)
    }
}