//! Macros used by this crate /// Implements the following traits for a newtype of a `der` decodable/encodable type: /// /// - `From` conversions to/from the inner type /// - `AsRef` and `AsMut` /// - `DecodeValue` and `EncodeValue` /// - `FixedTag` mapping to the inner value's `FixedTag::TAG` /// /// The main case is simplifying newtypes which need an `AssociatedOid` #[macro_export] macro_rules! impl_newtype { ($newtype:ty, $inner:ty) => { #[allow(unused_lifetimes)] impl<'a> From<$inner> for $newtype { #[inline] fn from(value: $inner) -> Self { Self(value) } } #[allow(unused_lifetimes)] impl<'a> From<$newtype> for $inner { #[inline] fn from(value: $newtype) -> Self { value.0 } } #[allow(unused_lifetimes)] impl<'a> AsRef<$inner> for $newtype { #[inline] fn as_ref(&self) -> &$inner { &self.0 } } #[allow(unused_lifetimes)] impl<'a> AsMut<$inner> for $newtype { #[inline] fn as_mut(&mut self) -> &mut $inner { &mut self.0 } } #[allow(unused_lifetimes)] impl<'a> ::der::FixedTag for $newtype { const TAG: ::der::Tag = <$inner as ::der::FixedTag>::TAG; } impl<'a> ::der::DecodeValue<'a> for $newtype { fn decode_value>( decoder: &mut R, header: ::der::Header, ) -> ::der::Result { Ok(Self(<$inner as ::der::DecodeValue>::decode_value( decoder, header, )?)) } } #[allow(unused_lifetimes)] impl<'a> ::der::EncodeValue for $newtype { fn encode_value(&self, encoder: &mut dyn ::der::Writer) -> ::der::Result<()> { self.0.encode_value(encoder) } fn value_len(&self) -> ::der::Result<::der::Length> { self.0.value_len() } } #[allow(unused_lifetimes)] impl<'a> ::der::ValueOrd for $newtype { fn value_cmp(&self, other: &Self) -> ::der::Result<::core::cmp::Ordering> { self.0.value_cmp(&other.0) } } }; }