#![cfg_attr(feature = "strict", deny(warnings))]
#![warn(missing_debug_implementations)]
macro_rules! raw_values {
($(#[$meta:meta])* CaseIterable $name:ident { $($case:ident = $raw:literal),* $(,)? }) => {
raw_values!(@enum $(#[$meta])* $name { $($case = $raw),* });
impl $name {
pub const ALL_CASES: &[Self] = &[$(Self::$case),*];
}
};
($(#[$meta:meta])* $name:ident { $($case:ident = $raw:literal),* $(,)? }) => {
raw_values!(@enum $(#[$meta])* $name { $($case = $raw),* });
impl $name {
#[cfg(all(test, target_os = "macos"))]
pub(crate) const ALL: &[Self] = &[$(Self::$case),*];
}
};
(@enum $(#[$meta:meta])* $name:ident { $($case:ident = $raw:literal),* $(,)? }) => {
$(#[$meta])*
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum $name {
$(#[doc = concat!("`", $raw, "`.")] $case),*
}
impl $name {
pub fn raw_value(self) -> &'static str {
match self {
$(Self::$case => $raw),*
}
}
pub fn from_raw_value(raw_value: &str) -> Option<Self> {
match raw_value {
$($raw => Some(Self::$case),)*
_ => None,
}
}
#[allow(dead_code)]
pub(crate) fn from_swift(raw_value: &str) -> Self {
Self::from_raw_value(raw_value)
.unwrap_or_else(|| panic!("Swift's {} has a case Rust lacks: {raw_value:?}", stringify!($name)))
}
}
impl AsRef<str> for $name {
fn as_ref(&self) -> &str {
self.raw_value()
}
}
impl std::str::FromStr for $name {
type Err = $crate::Error;
fn from_str(raw_value: &str) -> Result<Self, Self::Err> {
Self::from_raw_value(raw_value).ok_or_else(|| {
$crate::Error::failed(
concat!("parse a raw value of ", stringify!($name)),
format!("{raw_value:?} is not one of Swift's cases"),
)
})
}
}
};
}
pub mod cloud_hypervisor;
pub mod containerization;
pub mod containerization_archive;
pub mod containerization_error;
pub mod containerization_ext4;
pub mod containerization_extras;
pub mod containerization_io;
pub mod containerization_oci;
pub mod containerization_os;
pub mod versions;
mod error;
mod platform;
#[cfg(target_os = "macos")]
#[allow(clippy::too_many_arguments)]
mod bridge;
pub use crate::error::Error;