#![doc = include_str!("../README.md")]
#![no_std]
#[macro_export]
macro_rules! wrapper {
($($tt:tt)*) => {
$crate::__wrapper!($($tt)*);
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __wrapper {
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
#[cfg($($c:tt)+)]
$($rest:tt)*
) => {
$crate::__wrapper! {
@parse
[
$($cfg)*
#[cfg($($c)+)]
]
[
$($repr)*
]
[
$($bound)*
]
[
$($wrapper)*
]
[
$($meta)*
]
$($rest)*
}
};
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
#[repr($($r:tt)+)]
$($rest:tt)*
) => {
$crate::__wrapper! {
@parse
[
$($cfg)*
]
[
$($repr)*
#[repr($($r)+)]
]
[
$($bound)*
]
[
$($wrapper)*
]
[
$($meta)*
]
$($rest)*
}
};
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
#[bound($($b:tt)+)]
$($rest:tt)*
) => {
$crate::__wrapper! {
@parse
[
$($cfg)*
]
[
$($repr)*
]
[
$($b)+,
$($bound)*
]
[
$($wrapper)*
]
[
$($meta)*
]
$($rest)*
}
};
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
#[wrapper($($g:tt)+)]
$($rest:tt)*
) => {
$crate::__wrapper! {
@parse
[
$($cfg)*
]
[
$($repr)*
]
[
$($bound)*
]
[
$($wrapper)*
#[wrapper($($g)+)]
]
[
$($meta)*
]
$($rest)*
}
};
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
#[gen($($g:tt)+)]
$($rest:tt)*
) => {
$crate::__wrapper! {
@parse
[
$($cfg)*
]
[
$($repr)*
]
[
$($bound)*
]
[
$($wrapper)*
#[wrapper($($g)+)]
]
[
$($meta)*
]
$($rest)*
}
};
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
#[wrapper_impl($($g:tt)+)]
$($rest:tt)*
) => {
$crate::__wrapper! {
@parse
[
$($cfg)*
]
[
$($repr)*
]
[
$($bound)*
]
[
$($wrapper)*
#[wrapper($($g)+)]
]
[
$($meta)*
]
$($rest)*
}
};
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
#[$($m:tt)+]
$($rest:tt)*
) => {
$crate::__wrapper! {
@parse
[
$($cfg)*
]
[
$($repr)*
]
[
$($bound)*
]
[
$($wrapper)*
]
[
$($meta)*
#[$($m)+]
]
$($rest)*
}
};
(
@parse
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
$($rest:tt)*
) => {
$crate::__wrapper! {
@emit
[
$($cfg)*
]
[
$($repr)*
]
[
$($bound)*
]
[
$($wrapper)*
]
[
$($meta)*
]
$($rest)*
}
};
(
@emit
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? ($ivis:vis $ity:ty $(,)?);
) => {
$crate::__wrapper! {
@emit
[
$($cfg)*
]
[
$($repr)*
]
[
$($bound)*
]
[
$($wrapper)*
]
[
$($meta)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
/// The inner value being wrapped in this wrapper type.
$ivis inner: $ity,
}
}
};
(
@emit
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
#[default($($fdefault:tt)*)]
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$crate::__wrapper_type! {
$($cfg)*
$($repr)*
$($meta)*
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)?
where
$($bound)*
{
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? $name$(<$($lt),+>)?
where
$($bound)*
{
#[allow(dead_code)]
#[inline]
#[doc = concat!(" Wraps the given inner value with [`", stringify!($name), "`]")]
#[doc = ""]
#[doc = " The other fields will be each set to the specified default value."]
$ivis const fn from_inner($inner: $ity) -> Self {
Self {
$inner,
$(
$field: $($fdefault)*,
)*
}
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
#[default($($fdefault)*)]
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@emit
[
$($cfg:tt)*
]
[
$($repr:tt)*
]
[
$($bound:tt)*
]
[
$($wrapper:tt)*
]
[
$($meta:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$crate::__wrapper_type! {
$($cfg)*
$($repr)*
$($meta)*
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)?
where
$($bound)*
{
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
// ! Generating implementation.
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(Debug)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)?
where
$ity: ::core::fmt::Debug,
$($bound)*
{
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
::core::fmt::Debug::fmt(&self.$inner, f)
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(DebugName)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)?
where
$($bound)*
{
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct(stringify!($name)).finish()
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(Display)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::fmt::Display for $name$(<$($lt),+>)?
where
$ity: ::core::fmt::Display,
$($bound)*
{
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
::core::fmt::Display::fmt(&self.$inner, f)
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(AsRef)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? $name$(<$($lt),+>)?
where
$($bound)*
{
#[allow(dead_code)]
#[inline]
#[doc = concat!(" Returns a reference to the inner value of the [`", stringify!($name), "`].")]
$vis const fn as_inner(&self) -> &$ity {
&self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
#[wrapper(AsRef<$ity>)]
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(AsRef<$tty:ty>)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::convert::AsRef<$tty> for $name$(<$($lt),+>)?
where
$($bound)*
{
fn as_ref(&self) -> &$tty {
&self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper($([$cst:tt])?AsMut)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? $name$(<$($lt),+>)?
where
$($bound)*
{
#[allow(dead_code)]
#[inline]
#[doc = concat!(" Returns a mutable reference to the inner value of [`", stringify!($name), "`].")]
$vis $($cst)? fn as_inner_mut(&mut self) -> &mut $ity {
&mut self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
#[wrapper(AsMut<$ity>)]
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(AsMut<$tty:ty>)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::convert::AsMut<$tty> for $name$(<$($lt),+>)?
where
$($bound)*
{
fn as_mut(&mut self) -> &mut $tty {
&mut self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(Borrow)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
#[wrapper(Borrow<$ity>)]
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(Borrow<$tty:ty>)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::borrow::Borrow<$tty> for $name$(<$($lt),+>)?
where
$($bound)*
{
fn borrow(&self) -> &$tty {
&self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(BorrowMut)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
#[wrapper(BorrowMut<$ity>)]
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(BorrowMut<$tty:ty>)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::borrow::Borrow<$tty> for $name$(<$($lt),+>)?
where
$($bound)*
{
fn borrow(&self) -> &$tty {
&self.$inner
}
}
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::borrow::BorrowMut<$tty> for $name$(<$($lt),+>)?
where
$($bound)*
{
fn borrow_mut(&mut self) -> &mut $tty {
&mut self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(Deref)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
#[wrapper(Deref<$ity>)]
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(Deref<$tty:ty>)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)?
where
$($bound)*
{
type Target = $tty;
fn deref(&self) -> &$tty {
&self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(DerefMut)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
#[wrapper(DerefMut<$ity>)]
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(DerefMut<$tty:ty>)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)?
where
$($bound)*
{
type Target = $tty;
fn deref(&self) -> &$tty {
&self.$inner
}
}
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)?
where
$($bound)*
{
fn deref_mut(&mut self) -> &mut $tty {
&mut self.$inner
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(From)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
#[default($($fdefault:tt)*)]
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? $name$(<$($lt),+>)?
where
$($bound)*
{
#[allow(dead_code)]
#[doc = concat!(" Wraps the given inner value with [`", stringify!($name), "`]")]
#[doc = ""]
#[doc = " The other fields will be each set to the specified default value."]
$vis const fn from($inner: $ity) -> Self {
Self {
$inner,
$(
$field: $($fdefault)*,
)*
}
}
}
$($cfg)*
impl$(<$($lt$(:$blt$(+$mblt)*)?),+>)? ::core::convert::From<$ity> for $name$(<$($lt),+>)?
where
$($bound)*
{
fn from($inner: $ity) -> Self {
Self {
$inner,
$(
$field: $($fdefault)*,
)*
}
}
}
$crate::__wrapper! {
@gen
[
$($cfg)*
]
[
$($bound)*
]
[
$($wrapper)*
]
$vis struct $name$(<$($lt$(:$blt$(+$mblt)*)?$(=$default)?),+>)? {
$(#[$($imeta)*])*
$ivis $inner: $ity,
$(
#[default($($fdefault)*)]
$(#[$($fmeta)*])*
$fvis $field: $fty,
)*
}
}
};
(
@gen
[
$($cfg:tt)*
]
[
$($bound:tt)*
]
[
#[wrapper(From)]
$($wrapper:tt)*
]
$vis:vis struct $name:ident$(<$($lt:tt$(:$blt:tt$(+$mblt:tt)*)?$(=$default:ty)?),+>)? {
$(#[$($imeta:tt)*])*
$ivis:vis $inner:ident: $ity:ty
$(
,
$(#[$($fmeta:tt)*])*
$fvis:vis $field:ident: $fty:ty
)*
$(,)?
}
) => {
compile_error!(
"Fields except `inner` should be each provided a default value for implementing `From`."
);
};
(@ $($other:tt)*) => {
compile_error!(
"Incorrect or unsupported syntax, please refer to `wrapper!`'s documentation."
);
};
($($input:tt)*) => {
$crate::__wrapper! {
@parse [] [] [] [] [] $($input)*
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __wrapper_type {
(
#[repr(align(cache))]
$($tt:tt)*
) => {
#[cfg_attr(
any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "arm64ec",
target_arch = "powerpc64",
),
repr(align(128))
)]
#[cfg_attr(
any(
target_arch = "arm",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "mips64",
target_arch = "mips64r6",
target_arch = "sparc",
target_arch = "hexagon",
),
repr(align(32))
)]
#[cfg_attr(target_arch = "m68k", repr(align(16)))]
#[cfg_attr(target_arch = "s390x", repr(align(256)))]
#[cfg_attr(
not(any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "arm64ec",
target_arch = "powerpc64",
target_arch = "arm",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "mips64",
target_arch = "mips64r6",
target_arch = "sparc",
target_arch = "hexagon",
target_arch = "m68k",
target_arch = "s390x",
)),
repr(align(64))
)]
$($tt)*
};
($($tt:tt)*) => {
$($tt)*
};
}
#[deprecated(since = "0.5.0", note = "Use `wrapper!` instead")]
#[macro_export]
#[doc(hidden)]
macro_rules! general_wrapper {
($($tt:tt)+) => {
$crate::wrapper! {
#[wrapper(AsRef)]
#[wrapper(Borrow)]
#[wrapper(From)]
$($tt)+
}
};
}
#[deprecated(since = "0.5.0", note = "Use `wrapper!` instead")]
#[macro_export]
#[doc(hidden)]
macro_rules! aligned {
($($tt:tt)+) => {
$crate::wrapper! {
#[repr(align(cache))]
$($tt)+
}
};
}
wrapper!(
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(From)]
#[allow(dead_code)]
struct TestConstFromFromInnerAsInner<T> {
inner: T,
}
);