Skip to content

Commit

Permalink
core: Add Client enum
Browse files Browse the repository at this point in the history
This enum can be used in const assertions to ensure that all required
crate features have been selected, for example in backends.
  • Loading branch information
robin-nitrokey committed Dec 16, 2024
1 parent cfcaf94 commit 13e6501
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@ pub use management::ManagementClient;
#[cfg(feature = "ui-client")]
pub use ui::UiClient;

/// Available client traits.
///
/// This enum does not provide access to the trait features. It is only intended for backends to
/// use in constant assertions to ensure that the correct features are enabled.
#[non_exhaustive]
pub enum Client {
AttestClient,
CertificateClient,
CounterClient,
CryptoClient,
FilesystemClient,
ManagementClient,
UiClient,
}

impl Client {
/// All enabled clients.
///
/// The contents of this constant depends on the enabled features.
pub const ENABLED: &[Self] = &[
#[cfg(feature = "attest-client")]
Self::AttestClient,
#[cfg(feature = "certificate-client")]
Self::CertificateClient,
#[cfg(feature = "counter-client")]
Self::CounterClient,
#[cfg(feature = "crypto-client")]
Self::CryptoClient,
#[cfg(feature = "filesystem-client")]
Self::FilesystemClient,
#[cfg(feature = "management-client")]
Self::ManagementClient,
#[cfg(feature = "ui-client")]
Self::UiClient,
];
}

// to be fair, this is a programmer error,
// and could also just panic
#[derive(Copy, Clone, Debug)]
Expand Down

0 comments on commit 13e6501

Please sign in to comment.