Skip to main content

qubit_spi/
provider_availability.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Runtime availability state for service providers.
11
12/// Availability of a provider in the current runtime environment.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum ProviderAvailability {
15    /// The provider can create service instances.
16    Available,
17    /// The provider cannot create service instances.
18    Unavailable {
19        /// Human-readable reason explaining why the provider is unavailable.
20        reason: String,
21    },
22}
23
24impl ProviderAvailability {
25    /// Creates an unavailable state with a human-readable reason.
26    ///
27    /// # Parameters
28    /// - `reason`: Reason shown to callers when the provider cannot be used.
29    ///
30    /// # Returns
31    /// Unavailable provider state.
32    #[inline]
33    pub fn unavailable(reason: &str) -> Self {
34        Self::Unavailable {
35            reason: reason.to_owned(),
36        }
37    }
38
39    /// Tells whether this state allows service creation.
40    ///
41    /// # Returns
42    /// `true` when the provider is available.
43    #[inline]
44    pub fn is_available(&self) -> bool {
45        matches!(self, Self::Available)
46    }
47}