#[macro_export]
macro_rules! impl_bitflags {
($($ty:ty),+ $(,)?) => {
$(
impl $crate::RawRepr for $ty {
type Raw = <<$ty as $crate::__bitflags::Flags>::Bits as $crate::RawRepr>::Raw;
fn to_raw(&self) -> Self::Raw {
$crate::RawRepr::to_raw(&$crate::__bitflags::Flags::bits(self))
}
}
impl $crate::FromRawRepr for $ty {
fn from_raw(raw: Self::Raw) -> Self {
let bits = <<$ty as $crate::__bitflags::Flags>::Bits as $crate::FromRawRepr>::from_raw(raw);
<$ty as $crate::__bitflags::Flags>::from_bits_retain(bits)
}
}
impl $crate::TryFromRawRepr for $ty {
fn try_from_raw(raw: Self::Raw) -> Result<Self, $crate::DecodeError> {
Ok(<$ty as $crate::FromRawRepr>::from_raw(raw))
}
}
impl $crate::ToByteArray for $ty {
type ByteArray = <<$ty as $crate::RawRepr>::Raw as $crate::ToByteArray>::ByteArray;
fn to_byte_array(&self) -> Self::ByteArray {
$crate::ToByteArray::to_byte_array(&$crate::RawRepr::to_raw(self))
}
}
impl $crate::FromByteArray for $ty {
fn from_byte_array(byte_array: Self::ByteArray) -> Self {
let raw = <<$ty as $crate::RawRepr>::Raw as $crate::FromByteArray>::from_byte_array(byte_array);
<$ty as $crate::FromRawRepr>::from_raw(raw)
}
}
impl $crate::WireFingerprint for $ty {
const WIRE_FINGERPRINT: u64 = <<$ty as $crate::__bitflags::Flags>::Bits as $crate::WireFingerprint>::WIRE_FINGERPRINT;
}
)+
};
}
#[macro_export]
macro_rules! impl_bitflags_endian {
($($ty:ty),+ $(,)?) => {
$(
impl $crate::HasEndianRepr for $ty {
type LE = <<$ty as $crate::__bitflags::Flags>::Bits as $crate::HasEndianRepr>::LE;
type BE = <<$ty as $crate::__bitflags::Flags>::Bits as $crate::HasEndianRepr>::BE;
fn to_little_endian(self) -> Self::LE {
$crate::HasEndianRepr::to_little_endian($crate::__bitflags::Flags::bits(&self))
}
fn to_big_endian(self) -> Self::BE {
$crate::HasEndianRepr::to_big_endian($crate::__bitflags::Flags::bits(&self))
}
}
impl $crate::FromEndianRepr for $ty {
fn from_little_endian(le: Self::LE) -> Self {
let bits = $crate::FromEndianRepr::from_little_endian(le);
<$ty as $crate::__bitflags::Flags>::from_bits_retain(bits)
}
fn from_big_endian(be: Self::BE) -> Self {
let bits = $crate::FromEndianRepr::from_big_endian(be);
<$ty as $crate::__bitflags::Flags>::from_bits_retain(bits)
}
}
)+
};
}