qubit-fs 0.2.2

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.
// =============================================================================
// property contract tests.
//! Compact immutable sets of provider operation entry points.

use super::ProviderOperation;

/// Immutable set of concrete operation entry points implemented by a provider.
///
/// # Examples
///
/// ```rust
/// use qubit_fs::spi::{ProviderOperation, ProviderOperations};
///
/// let ops = ProviderOperations::new().with(ProviderOperation::Stat);
/// assert!(ops.supports(ProviderOperation::Stat));
/// ```
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct ProviderOperations {
    /// Bit flags indexed by [`ProviderOperation`] discriminants.
    bits: u128,
}

impl ProviderOperations {
    /// Creates an empty provider-operation set.
    ///
    /// # Returns
    /// A set containing no provider operation entry points.
    #[inline]
    #[must_use]
    pub const fn new() -> Self {
        Self { bits: 0 }
    }

    /// Returns a copy containing `operation`.
    ///
    /// # Parameters
    /// - `operation`: Provider entry point to insert.
    ///
    /// # Returns
    /// The updated immutable operation set.
    #[inline]
    #[must_use]
    pub const fn with(mut self, operation: ProviderOperation) -> Self {
        self.bits |= 1_u128 << operation as u8;
        self
    }

    /// Returns whether the provider implements `operation`.
    ///
    /// # Parameters
    /// - `operation`: Provider entry point to query.
    ///
    /// # Returns
    /// `true` when the operation is present in this snapshot.
    #[inline]
    #[must_use]
    pub const fn supports(&self, operation: ProviderOperation) -> bool {
        self.bits & (1_u128 << operation as u8) != 0
    }
}