qubit_fs/spi/provider_operations.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// property contract tests.
9//! Compact immutable sets of provider operation entry points.
10
11use super::ProviderOperation;
12
13/// Immutable set of concrete operation entry points implemented by a provider.
14///
15/// # Examples
16///
17/// ```rust
18/// use qubit_fs::spi::{ProviderOperation, ProviderOperations};
19///
20/// let ops = ProviderOperations::new().with(ProviderOperation::Stat);
21/// assert!(ops.supports(ProviderOperation::Stat));
22/// ```
23#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
24pub struct ProviderOperations {
25 /// Bit flags indexed by [`ProviderOperation`] discriminants.
26 bits: u128,
27}
28
29impl ProviderOperations {
30 /// Creates an empty provider-operation set.
31 ///
32 /// # Returns
33 /// A set containing no provider operation entry points.
34 #[inline]
35 #[must_use]
36 pub const fn new() -> Self {
37 Self { bits: 0 }
38 }
39
40 /// Returns a copy containing `operation`.
41 ///
42 /// # Parameters
43 /// - `operation`: Provider entry point to insert.
44 ///
45 /// # Returns
46 /// The updated immutable operation set.
47 #[inline]
48 #[must_use]
49 pub const fn with(mut self, operation: ProviderOperation) -> Self {
50 self.bits |= 1_u128 << operation as u8;
51 self
52 }
53
54 /// Returns whether the provider implements `operation`.
55 ///
56 /// # Parameters
57 /// - `operation`: Provider entry point to query.
58 ///
59 /// # Returns
60 /// `true` when the operation is present in this snapshot.
61 #[inline]
62 #[must_use]
63 pub const fn supports(&self, operation: ProviderOperation) -> bool {
64 self.bits & (1_u128 << operation as u8) != 0
65 }
66}