#![cfg_attr(feature = "docs", doc = "\n\nSee the [changelog][changelog] for a full release history.")]
#![cfg_attr(feature = "docs", doc = "## Feature flags")]
#![cfg_attr(feature = "docs", doc = document_features::document_features!())]
#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![deny(missing_docs)]
#![deny(unsafe_code)]
#![deny(unreachable_pub)]
#[macro_export]
macro_rules! nutype_enum {
(
$(#[$attr:meta])*
$vis:vis enum $name:ident($type:ty) {
$(
$(#[$variant_attr:meta])*
$variant:ident = $value:expr
),*$(,)?
}
) => {
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
$(#[$attr])*
#[repr(transparent)]
$vis struct $name(pub $type);
impl ::std::fmt::Debug for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
$(
&$name::$variant => write!(f, "{}::{}", stringify!($name), stringify!($variant)),
)*
_ => write!(f, "{}({:?})", stringify!($name), self.0),
}
}
}
impl $name {
$(
$(#[$variant_attr])*
#[allow(non_upper_case_globals)]
pub const $variant: Self = Self($value);
)*
}
impl From<$type> for $name {
fn from(value: $type) -> Self {
Self(value)
}
}
impl From<$name> for $type {
fn from(value: $name) -> Self {
value.0
}
}
};
}
#[macro_export]
macro_rules! bitwise_enum {
($name:ident) => {
impl ::std::ops::BitAnd for $name {
type Output = Self;
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0)
}
}
impl ::std::ops::BitOr for $name {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}
impl ::std::ops::BitXor for $name {
type Output = Self;
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0 ^ rhs.0)
}
}
impl ::std::ops::Not for $name {
type Output = Self;
fn not(self) -> Self::Output {
Self(!self.0)
}
}
impl ::std::ops::BitAndAssign for $name {
fn bitand_assign(&mut self, rhs: Self) {
self.0 &= rhs.0;
}
}
impl ::std::ops::BitOrAssign for $name {
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0;
}
}
impl ::std::ops::BitXorAssign for $name {
fn bitxor_assign(&mut self, rhs: Self) {
self.0 ^= rhs.0;
}
}
};
}
#[cfg(feature = "docs")]
#[scuffle_changelog::changelog]
pub mod changelog {}