#![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"),
)
})
}
}
};
}
macro_rules! opaque_debug {
($(#[$meta:meta])* $name:ident $(<$lifetime:lifetime>)?) => {
$(#[$meta])*
impl std::fmt::Debug for $name $(<$lifetime>)? {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.debug_struct(stringify!($name)).finish_non_exhaustive()
}
}
};
}
macro_rules! same_variants {
($rust:ty, $bridge:ty { $($variant:ident $(=> $renamed:ident)?),* $(,)? }) => {
impl From<$rust> for $bridge {
fn from(value: $rust) -> Self {
type Rust = $rust;
match value {
$(Rust::$variant => same_variants!(@bridge $variant $($renamed)?)),*
}
}
}
impl From<$bridge> for $rust {
fn from(value: $bridge) -> Self {
type Bridge = $bridge;
match value {
$(same_variants!(@pattern $variant $($renamed)?) => Self::$variant),*
}
}
}
};
(@bridge $variant:ident) => { Self::$variant };
(@bridge $variant:ident $renamed:ident) => { Self::$renamed };
(@pattern $variant:ident) => { Bridge::$variant };
(@pattern $variant:ident $renamed:ident) => { Bridge::$renamed };
}
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;
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;