wrapper_lite/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3
4#[macro_export]
5/// Helper macro for creating a wrapper over any type (new-type idiom).
6///
7/// This is a shortcut for using the [`wrapper!`] macro with the most common
8/// impls (`AsRef`, `Borrow`, `From`).
9///
10/// ```rust
11/// wrapper_lite::general_wrapper!(
12///     #[derive(Debug, Clone, Copy)]
13///     pub struct ExampleWrapper<'a, P>(pub(crate) &'a P);
14/// );
15/// ```
16///
17/// This is equivalent to using the `wrapper!` macro with the following
18/// attributes:
19///
20/// ```rust
21/// wrapper_lite::wrapper!(
22///     #[wrapper_impl(AsRef)]
23///     #[wrapper_impl(Borrow)]
24///     #[wrapper_impl(From)]
25///     #[derive(Debug, Clone, Copy)]
26///     pub struct ExampleWrapper<'a, P>(pub(crate) &'a P);
27/// );
28/// ```
29///
30/// You can certainly add attributes like `#[wrapper_impl(Deref)]` other than
31/// the preset ones. See [`wrapper!`] for more details.
32///
33/// ```rust
34/// wrapper_lite::general_wrapper!(
35///     #[wrapper_impl(Deref)]
36///     #[derive(Debug, Clone, Copy)]
37///     pub struct ExampleWrapper<'a, P>(pub(crate) &'a P);
38/// );
39/// ```
40macro_rules! general_wrapper {
41    ($($tt:tt)+) => {
42        $crate::wrapper! {
43            #[wrapper_impl(AsRef)]
44            #[wrapper_impl(Borrow)]
45            #[wrapper_impl(From)]
46            $($tt)+
47        }
48    };
49}
50
51#[macro_export]
52/// Helper macro for creating a wrapper over any type (new-type idiom).
53///
54/// # Usage
55///
56/// It's worth noting that `wrapper! { ... }` is almost equivalent to
57/// `wrapper!( ... );` but lacking cargo-fmt support. We recommend using the
58/// latter.
59///
60/// ## Usage: basic
61///
62/// ```rust
63/// wrapper_lite::wrapper!(
64///     #[wrapper_impl(AsRef)]
65///     #[wrapper_impl(AsMut)]
66///     // #[wrapper_impl(Borrow)]
67///     #[wrapper_impl(BorrowMut)]
68///     // #[wrapper_impl(Deref)]
69///     #[wrapper_impl(DerefMut)]
70///     #[wrapper_impl(From)]
71///     #[derive(Debug, Clone, Copy)]
72///     pub struct ExampleWrapper<'a, P>(pub(crate) &'a P);
73/// );
74/// ```
75///
76/// Generates const accessor methods for wrapper types implementing `AsRef` and
77/// `AsMut` traits.
78///
79/// For types implementing `AsRef`, this creates a const method `as_inner` that
80/// returns a reference to the wrapped value. For types implementing `AsMut`,
81/// this creates a const method `as_inner_mut` that returns a mutable reference
82/// to the wrapped value.
83///
84/// Additionally generates a const constructor method `const_from` for the
85/// wrapper type, using the same visibility as the inner field. When the `From`
86/// trait is implemented, also generates a public const method `from`.
87///
88/// ## Usage: advanced
89///
90/// You can also create a wrapper type with a struct with multiple fields,
91/// especially when some lifetime markers or generics markers are too complex,
92/// or you need some custom fields.
93///
94/// Here's an complex example:
95///
96/// ```rust
97/// wrapper_lite::wrapper!(
98///     #[wrapper_impl(AsMut)]
99///     #[wrapper_impl(AsRef)]
100///     // #[wrapper_impl(Borrow)]
101///     #[wrapper_impl(BorrowMut)]
102///     // #[wrapper_impl(Deref)]
103///     #[wrapper_impl(DerefMut)]
104///     // #[wrapper_impl(From)]
105///     #[wrapper_impl(Debug)]
106///     #[derive(Clone, Copy, PartialEq, Eq)]
107///     #[repr(transparent)]
108///     pub struct ExampleWrapperComplex<'a, 'b, P> {
109///         inner: P,
110///         _a: ::core::marker::PhantomData<&'a ()>,
111///         _b: ::core::marker::PhantomData<&'b ()>,
112///     }
113/// );
114///
115/// wrapper_lite::wrapper!(
116///     #[wrapper_impl(AsMut)]
117///     #[wrapper_impl(AsRef)]
118///     // #[wrapper_impl(Borrow)]
119///     #[wrapper_impl(BorrowMut)]
120///     // #[wrapper_impl(Deref)]
121///     #[wrapper_impl(DerefMut)]
122///     #[wrapper_impl(From)]
123///     #[wrapper_impl(Debug)]
124///     #[derive(Clone, Copy, PartialEq, Eq)]
125///     #[repr(transparent)]
126///     pub struct ExampleWrapperComplexWithDefault<'a, 'b, P> {
127///         inner: P,
128///         _a: ::core::marker::PhantomData<&'a ()> = ::core::marker::PhantomData,
129///         _b: ::core::marker::PhantomData<&'b ()> = ::core::marker::PhantomData,
130///     }
131/// );
132/// ```
133///
134/// There're some limitations:
135///
136/// - The inner field must be named as `inner`.
137/// - When there's no default value specified, we cannot implement the `From`
138///   trait for the wrapper type.
139/// - The macro does not know if other fields were zero-sized types (ZST), hence
140///   we will not automatically apply `repr(transparent)` attribute.
141///
142/// ## Special usages
143///
144/// ### `Debug` and `DebugName`
145///
146/// We offer `Debug` and `DebugName` attributes to control how the wrapper type
147/// is printed when using the `Debug` trait, instead of `#[derive(Debug)]`.
148///
149/// - `#[wrapper_impl(Debug)]`: transparently implements the `Debug` trait if
150///   the inner type implements it. The debug output is the same as the inner
151///   one.
152/// - `#[wrapper_impl(DebugName)]`: implements the `Debug` trait, but only
153///   prints the name of the wrapper type.
154///
155/// ```rust
156/// wrapper_lite::wrapper!(
157///     #[wrapper_impl(Debug)]
158///     #[derive(Clone, Copy)]
159///     pub struct ExampleWrapperDebug<'a, P>(&'a P);
160/// );
161///
162/// wrapper_lite::wrapper!(
163///     #[wrapper_impl(DebugName)]
164///     #[derive(Clone, Copy)]
165///     pub struct ExampleWrapperDebugName<'a, P>(&'a P);
166/// );
167///
168/// let data = "Hello".to_string();
169///
170/// // Here we transparently print the debug output of the inner type.
171/// assert_eq!(
172///     format!("{:?}", ExampleWrapperDebug { inner: &data }),
173///     "\"Hello\""
174/// );
175/// // Here we only print the name of the wrapper type.
176/// assert_eq!(
177///     format!("{:?}", ExampleWrapperDebugName { inner: &data }),
178///     "ExampleWrapperDebugName"
179/// );
180/// ```
181///
182/// ### `ConstAsMut`
183///
184/// Like `AsMut`, but instead generates a const version of `as_inner_mut` method
185/// (stable since Rust 1.83.0+).
186///
187/// ```rust,no_run
188/// wrapper_lite::wrapper!(
189///     #[wrapper_impl(ConstAsMut)]
190///     #[derive(Debug, Clone, Copy)]
191///     pub struct ExampleWrapper<P>(pub(crate) P);
192/// );
193///
194/// const fn const_fn_example<P>(w: &mut ExampleWrapper<P>) -> &mut P {
195///     w.as_inner_mut()
196/// }
197/// ```
198///
199/// ### `AsRef<T>`, `AsMut<T>`, `Borrow<T>`, `BorrowMut<T>`, `Deref<T>`, `DerefMut<T>`
200///
201/// These attributes allow you to specify a target type `T` for the respective
202/// traits (experimental). This is done by auto-dereferencing the inner type to
203/// get a reference to `T`.
204///
205/// ```rust
206/// wrapper_lite::wrapper!(
207///     #[wrapper_impl(AsRef<[u8]>)]
208///     #[wrapper_impl(AsMut<[u8]>)]
209///     // #[wrapper_impl(Borrow<[u8]>)]
210///     #[wrapper_impl(BorrowMut<[u8]>)]
211///     // #[wrapper_impl(Deref<[u8]>)]
212///     #[wrapper_impl(DerefMut<[u8]>)]
213///     pub struct ExampleWrapper(pub(crate) Vec<u8>);
214/// );
215/// ```
216///
217/// ## Notes
218///
219/// - The `wrapper_impl` attribute must be on top of any other attributes.
220/// - For `BorrowMut` and `DerefMut`, the macro will automatically implement the
221///   corresponding `Borrow` and `Deref` traits, so the following two examples
222///   will fail to compile:
223///
224///   ```rust,compile_fail
225///   wrapper_lite::wrapper!(
226///       #[wrapper_impl(Borrow)]
227///       #[wrapper_impl(BorrowMut)]
228///       pub struct ExampleWrapper<P>(pub(crate) P);
229///   );
230///   ```
231///
232///   ```rust,compile_fail
233///   wrapper_lite::wrapper!(
234///       #[wrapper_impl(Deref)]
235///       #[wrapper_impl(DerefMut)]
236///       pub struct ExampleWrapper<P>(pub(crate) P);
237///   );
238///   ```
239macro_rules! wrapper {
240    // To filter out the `wrapper_impl` attribute and extract the inner type.
241    (
242        @INTERNAL IMPL
243        #[wrapper_impl(AsRef $(<$target:ty>)? )]
244        $($tt:tt)*
245    ) => {
246        $crate::wrapper! {
247            @INTERNAL IMPL
248            $($tt)*
249        }
250    };
251    (
252        @INTERNAL IMPL
253        #[wrapper_impl(AsMut $(<$target:ty>)? )]
254        $($tt:tt)*
255    ) => {
256        $crate::wrapper! {
257            @INTERNAL IMPL
258            $($tt)*
259        }
260    };
261    (
262        @INTERNAL IMPL
263        #[wrapper_impl(ConstAsMut $(<$target:ty>)? )]
264        $($tt:tt)*
265    ) => {
266        $crate::wrapper! {
267            @INTERNAL IMPL
268            $($tt)*
269        }
270    };
271    (
272        @INTERNAL IMPL
273        #[wrapper_impl(Borrow $(<$target:ty>)? )]
274        $($tt:tt)*
275    ) => {
276        $crate::wrapper! {
277            @INTERNAL IMPL
278            $($tt)*
279        }
280    };
281    (
282        @INTERNAL IMPL
283        #[wrapper_impl(BorrowMut $(<$target:ty>)? )]
284        $($tt:tt)*
285    ) => {
286        $crate::wrapper! {
287            @INTERNAL IMPL
288            $($tt)*
289        }
290    };
291    (
292        @INTERNAL IMPL
293        #[wrapper_impl(Deref $(<$target:ty>)? )]
294        $($tt:tt)*
295    ) => {
296        $crate::wrapper! {
297            @INTERNAL IMPL
298            $($tt)*
299        }
300    };
301    (
302        @INTERNAL IMPL
303        #[wrapper_impl(DerefMut $(<$target:ty>)? )]
304        $($tt:tt)*
305    ) => {
306        $crate::wrapper! {
307            @INTERNAL IMPL
308            $($tt)*
309        }
310    };
311    (
312        @INTERNAL IMPL
313        #[wrapper_impl(From)]
314        $($tt:tt)*
315    ) => {
316        $crate::wrapper! {
317            @INTERNAL IMPL
318            $($tt)*
319        }
320    };
321    (
322        @INTERNAL IMPL
323        #[wrapper_impl(Debug)]
324        $($tt:tt)*
325    ) => {
326        $crate::wrapper! {
327            @INTERNAL IMPL
328            $($tt)*
329        }
330    };
331    (
332        @INTERNAL IMPL
333        #[wrapper_impl(DebugName)]
334        $($tt:tt)*
335    ) => {
336        $crate::wrapper! {
337            @INTERNAL IMPL
338            $($tt)*
339        }
340    };
341
342    // The actual implementation of the wrapper type: `pub Name<...>(...)`
343    (
344        @INTERNAL IMPL
345        $(#[$outer:meta])*
346        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
347    ) => {
348        $(#[$outer])*
349        #[repr(transparent)]
350        $vis struct $name$(<$($lt),+>)? {
351            /// Inner value
352            $inner_vis inner: $inner_ty,
353        }
354
355        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
356            #[inline(always)]
357            #[doc = concat!("Creates a new instance of [`", stringify!($name), "`]")]
358            $inner_vis const fn const_from(inner: $inner_ty) -> Self {
359                Self {
360                    inner,
361                }
362            }
363        }
364    };
365
366    // The actual implementation of the wrapper type: `pub struct Name<...> { ... }`
367    // with field initial value provided, make `const_from` const.
368    (
369        @INTERNAL IMPL
370        $(#[$outer:meta])*
371        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
372            $(#[$field_inner_meta:meta])*
373            $inner_vis:vis inner: $inner_ty:ty
374            $(
375                ,
376                $(#[$field_meta:meta])*
377                $field_vis:vis $field:ident: $field_ty:ty = $field_default: expr
378            )*
379            $(,)?
380        }
381    ) => {
382        $(#[$outer])*
383        $vis struct $name$(<$($lt),+>)? {
384            $(#[$field_inner_meta])*
385            $inner_vis inner: $inner_ty,
386            $(
387                $(#[$field_meta])*
388                $field_vis $field: $field_ty
389            ),*
390        }
391
392        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
393            #[inline(always)]
394            #[doc = concat!("Creates a new instance of [`", stringify!($name), "`]")]
395            $inner_vis const fn const_from(inner: $inner_ty) -> Self {
396                Self {
397                    inner,
398                    $(
399                        $field: $field_default,
400                    )*
401                }
402            }
403        }
404    };
405
406    // The actual implementation of the wrapper type with fields: `pub struct Name<...> { ... }`
407    (
408        @INTERNAL IMPL
409        $(#[$outer:meta])*
410        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
411            $(#[$field_inner_meta:meta])*
412            $inner_vis:vis inner: $inner_ty:ty
413            $(
414                ,
415                $(#[$field_meta:meta])*
416                $field_vis:vis $field:ident: $field_ty:ty
417            )*
418            $(,)?
419        }
420    ) => {
421        $(#[$outer])*
422        $vis struct $name$(<$($lt),+>)? {
423            $(#[$field_inner_meta])*
424            $inner_vis inner: $inner_ty
425            $(
426                ,
427                $(#[$field_meta])*
428                $field_vis $field: $field_ty
429            )*
430        }
431    };
432
433    // === Process all `wrapper_impl` attributes, and generate impls. ===
434
435    // Extract wrapper impl for `AsRef` trait.
436    (
437        @INTERNAL WRAPPER_IMPL
438        #[wrapper_impl(AsRef $(<$target:ty>)? )]
439        $($tt:tt)*
440    ) => {
441        $crate::wrapper! {
442            @INTERNAL WRAPPER_IMPL_AS_REF $(<$target>)?
443            $($tt)*
444        }
445
446        $crate::wrapper! {
447            @INTERNAL WRAPPER_IMPL
448            $($tt)*
449        }
450    };
451
452    // Extract wrapper impl for `AsMut` trait.
453    (
454        @INTERNAL WRAPPER_IMPL
455        #[wrapper_impl(AsMut $(<$target:ty>)? )]
456        $($tt:tt)*
457    ) => {
458        $crate::wrapper! {
459            @INTERNAL WRAPPER_IMPL_AS_MUT $(<$target>)?
460            $($tt)*
461        }
462
463        $crate::wrapper! {
464            @INTERNAL WRAPPER_IMPL
465            $($tt)*
466        }
467    };
468
469    // Extract wrapper impl for `AsMut` trait, const version.
470    (
471        @INTERNAL WRAPPER_IMPL
472        #[wrapper_impl(ConstAsMut $(<$target:ty>)? )]
473        $($tt:tt)*
474    ) => {
475        $crate::wrapper! {
476            @INTERNAL WRAPPER_IMPL_CONST_AS_MUT $(<$target>)?
477            $($tt)*
478        }
479
480        $crate::wrapper! {
481            @INTERNAL WRAPPER_IMPL
482            $($tt)*
483        }
484    };
485
486    // Extract wrapper impl for `Borrow` trait.
487    (
488        @INTERNAL WRAPPER_IMPL
489        #[wrapper_impl(Borrow $(<$target:ty>)? )]
490        $($tt:tt)*
491    ) => {
492        $crate::wrapper! {
493            @INTERNAL WRAPPER_IMPL_BORROW $(<$target>)?
494            $($tt)*
495        }
496
497        $crate::wrapper! {
498            @INTERNAL WRAPPER_IMPL
499            $($tt)*
500        }
501    };
502
503    // Extract wrapper impl for `BorrowMut` trait.
504    (
505        @INTERNAL WRAPPER_IMPL
506        #[wrapper_impl(BorrowMut $(<$target:ty>)? )]
507        $($tt:tt)*
508    ) => {
509        $crate::wrapper! {
510            @INTERNAL WRAPPER_IMPL_BORROW $(<$target>)?
511            $($tt)*
512        }
513
514        $crate::wrapper! {
515            @INTERNAL WRAPPER_IMPL_BORROW_MUT $(<$target>)?
516            $($tt)*
517        }
518
519        $crate::wrapper! {
520            @INTERNAL WRAPPER_IMPL
521            $($tt)*
522        }
523    };
524
525    // Extract wrapper impl for `Debug` trait.
526    (
527        @INTERNAL WRAPPER_IMPL
528        #[wrapper_impl(Debug)]
529        $($tt:tt)*
530    ) => {
531        $crate::wrapper! {
532            @INTERNAL WRAPPER_IMPL_DEBUG
533            $($tt)*
534        }
535
536        $crate::wrapper! {
537            @INTERNAL WRAPPER_IMPL
538            $($tt)*
539        }
540    };
541
542    // Extract wrapper impl for `Debug` trait  printing its name only.
543    (
544        @INTERNAL WRAPPER_IMPL
545        #[wrapper_impl(DebugName)]
546        $($tt:tt)*
547    ) => {
548        $crate::wrapper! {
549            @INTERNAL WRAPPER_IMPL_DEBUG_NAME
550            $($tt)*
551        }
552
553        $crate::wrapper! {
554            @INTERNAL WRAPPER_IMPL
555            $($tt)*
556        }
557    };
558
559    // Extract wrapper impl for `Deref` trait.
560    (
561        @INTERNAL WRAPPER_IMPL
562        #[wrapper_impl(Deref $(<$target:ty>)? )]
563        $($tt:tt)*
564    ) => {
565        $crate::wrapper! {
566            @INTERNAL WRAPPER_IMPL_DEREF $(<$target>)?
567            $($tt)*
568        }
569
570        $crate::wrapper! {
571            @INTERNAL WRAPPER_IMPL
572            $($tt)*
573        }
574    };
575
576    // Extract wrapper impl for `DerefMut` trait (and `Deref`).
577    (
578        @INTERNAL WRAPPER_IMPL
579        #[wrapper_impl(DerefMut $(<$target:ty>)? )]
580        $($tt:tt)*
581    ) => {
582        $crate::wrapper! {
583            @INTERNAL WRAPPER_IMPL_DEREF $(<$target>)?
584            $($tt)*
585        }
586
587        $crate::wrapper! {
588            @INTERNAL WRAPPER_IMPL_DEREF_MUT $(<$target>)?
589            $($tt)*
590        }
591
592        $crate::wrapper! {
593            @INTERNAL WRAPPER_IMPL
594            $($tt)*
595        }
596    };
597
598    // Extract wrapper impl for `From` trait.
599    (
600        @INTERNAL WRAPPER_IMPL
601        #[wrapper_impl(From)]
602        $($tt:tt)*
603    ) => {
604        $crate::wrapper! {
605            @INTERNAL WRAPPER_IMPL_FROM
606            $($tt)*
607        }
608
609        $crate::wrapper! {
610            @INTERNAL WRAPPER_IMPL
611            $($tt)*
612        }
613    };
614
615    // ================ Impl `AsRef` trait for the wrapper type. ================
616    (
617        @INTERNAL WRAPPER_IMPL_AS_REF <$target:ty>
618        $(#[$meta:meta])*
619        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
620    ) => {
621        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$target> for $name$(<$($lt),+>)? {
622            fn as_ref(&self) -> &$target {
623                &self.inner
624            }
625        }
626    };
627    (
628        @INTERNAL WRAPPER_IMPL_AS_REF <$target:ty>
629        $(#[$meta:meta])*
630        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
631            $(#[$field_inner_meta:meta])*
632            $inner_vis:vis inner: $inner_ty:ty
633            $(
634                ,
635                $(#[$field_meta:meta])*
636                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
637            )*
638            $(,)?
639        }
640    ) => {
641        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$target> for $name$(<$($lt),+>)? {
642            fn as_ref(&self) -> &$target {
643                &self.inner
644            }
645        }
646    };
647    (
648        @INTERNAL WRAPPER_IMPL_AS_REF
649        $(#[$meta:meta])*
650        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
651    ) => {
652        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$inner_ty> for $name$(<$($lt),+>)? {
653            fn as_ref(&self) -> &$inner_ty {
654                &self.inner
655            }
656        }
657
658        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
659            /// Returns a reference to the inner value.
660            #[inline(always)]
661            pub const fn as_inner(&self) -> &$inner_ty {
662                &self.inner
663            }
664        }
665    };
666    (
667        @INTERNAL WRAPPER_IMPL_AS_REF
668        $(#[$meta:meta])*
669        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
670            $(#[$field_inner_meta:meta])*
671            $inner_vis:vis inner: $inner_ty:ty
672            $(
673                ,
674                $(#[$field_meta:meta])*
675                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
676            )*
677            $(,)?
678        }
679    ) => {
680        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$inner_ty> for $name$(<$($lt),+>)? {
681            fn as_ref(&self) -> &$inner_ty {
682                &self.inner
683            }
684        }
685
686        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
687            /// Returns a reference to the inner value.
688            #[inline(always)]
689            pub const fn as_inner(&self) -> &$inner_ty {
690                &self.inner
691            }
692        }
693    };
694    // ================ Impl `AsRef` trait for the wrapper type. ================
695
696
697    // ================ Impl `AsMut` trait for the wrapper type. ================
698    (
699        @INTERNAL WRAPPER_IMPL_AS_MUT <$target:ty>
700        $(#[$meta:meta])*
701        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
702    ) => {
703        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
704            fn as_mut(&mut self) -> &mut $target {
705                &mut self.inner
706            }
707        }
708    };
709    (
710        @INTERNAL WRAPPER_IMPL_AS_MUT <$target:ty>
711        $(#[$meta:meta])*
712        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
713            $(#[$field_inner_meta:meta])*
714            $inner_vis:vis inner: $inner_ty:ty
715            $(
716                ,
717                $(#[$field_meta:meta])*
718                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
719            )*
720            $(,)?
721        }
722    ) => {
723        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
724            #[inline(always)]
725            fn as_mut(&mut self) -> &mut $target {
726                &mut self.inner
727            }
728        }
729    };
730    (
731        @INTERNAL WRAPPER_IMPL_AS_MUT
732        $(#[$meta:meta])*
733        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
734    ) => {
735        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
736            fn as_mut(&mut self) -> &mut $inner_ty {
737                &mut self.inner
738            }
739        }
740
741        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
742            #[inline(always)]
743            /// Returns a mutable reference to the inner value.
744            pub fn as_inner_mut(&mut self) -> &mut $inner_ty {
745                &mut self.inner
746            }
747        }
748    };
749    (
750        @INTERNAL WRAPPER_IMPL_AS_MUT
751        $(#[$meta:meta])*
752        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
753            $(#[$field_inner_meta:meta])*
754            $inner_vis:vis inner: $inner_ty:ty
755            $(
756                ,
757                $(#[$field_meta:meta])*
758                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
759            )*
760            $(,)?
761        }
762    ) => {
763        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
764            #[inline(always)]
765            fn as_mut(&mut self) -> &mut $inner_ty {
766                &mut self.inner
767            }
768        }
769
770        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
771            #[inline(always)]
772            /// Returns a mutable reference to the inner value.
773            pub fn as_inner_mut(&mut self) -> &mut $inner_ty {
774                &mut self.inner
775            }
776        }
777    };
778    (
779        @INTERNAL WRAPPER_IMPL_CONST_AS_MUT <$target:ty>
780        $(#[$meta:meta])*
781        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
782    ) => {
783        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
784            fn as_mut(&mut self) -> &mut $target {
785                &mut self.inner
786            }
787        }
788    };
789    (
790        @INTERNAL WRAPPER_IMPL_CONST_AS_MUT
791        $(#[$meta:meta])*
792        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
793            $(#[$field_inner_meta:meta])*
794            $inner_vis:vis inner: $inner_ty:ty
795            $(
796                ,
797                $(#[$field_meta:meta])*
798                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
799            )*
800            $(,)?
801        }
802    ) => {
803        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
804            #[inline(always)]
805            fn as_mut(&mut self) -> &mut $target {
806                &mut self.inner
807            }
808        }
809    };
810    (
811        @INTERNAL WRAPPER_IMPL_CONST_AS_MUT
812        $(#[$meta:meta])*
813        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
814    ) => {
815        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
816            fn as_mut(&mut self) -> &mut $inner_ty {
817                &mut self.inner
818            }
819        }
820
821        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
822            #[inline(always)]
823            /// Returns a mutable reference to the inner value.
824            pub const fn as_inner_mut(&mut self) -> &mut $inner_ty {
825                &mut self.inner
826            }
827        }
828    };
829    (
830        @INTERNAL WRAPPER_IMPL_CONST_AS_MUT
831        $(#[$meta:meta])*
832        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
833            $(#[$field_inner_meta:meta])*
834            $inner_vis:vis inner: $inner_ty:ty
835            $(
836                ,
837                $(#[$field_meta:meta])*
838                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
839            )*
840            $(,)?
841        }
842    ) => {
843        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
844            #[inline(always)]
845            fn as_mut(&mut self) -> &mut $inner_ty {
846                &mut self.inner
847            }
848        }
849
850        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
851            #[inline(always)]
852            /// Returns a mutable reference to the inner value.
853            pub const fn as_inner_mut(&mut self) -> &mut $inner_ty {
854                &mut self.inner
855            }
856        }
857    };
858    // ================ Impl `AsMut` trait for the wrapper type. ================
859
860    // ================ Impl `Borrow` trait for the wrapper type. ================
861    (
862        @INTERNAL WRAPPER_IMPL_BORROW <$target:ty>
863        $(#[$meta:meta])*
864        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
865    ) => {
866        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$target> for $name$(<$($lt),+>)? {
867            fn borrow(&self) -> &$target {
868                &self.inner
869            }
870        }
871    };
872    (
873        @INTERNAL WRAPPER_IMPL_BORROW <$target:ty>
874        $(#[$meta:meta])*
875        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
876            $(#[$field_inner_meta:meta])*
877            $inner_vis:vis inner: $inner_ty:ty
878            $(
879                ,
880                $(#[$field_meta:meta])*
881                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
882            )*
883            $(,)?
884        }
885    ) => {
886        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$target> for $name$(<$($lt),+>)? {
887            fn borrow(&self) -> &$target {
888                &self.inner
889            }
890        }
891    };
892    (
893        @INTERNAL WRAPPER_IMPL_BORROW
894        $(#[$meta:meta])*
895        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
896    ) => {
897        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$inner_ty> for $name$(<$($lt),+>)? {
898            fn borrow(&self) -> &$inner_ty {
899                &self.inner
900            }
901        }
902    };
903    (
904        @INTERNAL WRAPPER_IMPL_BORROW
905        $(#[$meta:meta])*
906        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
907            $(#[$field_inner_meta:meta])*
908            $inner_vis:vis inner: $inner_ty:ty
909            $(
910                ,
911                $(#[$field_meta:meta])*
912                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
913            )*
914            $(,)?
915        }
916    ) => {
917        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$inner_ty> for $name$(<$($lt),+>)? {
918            fn borrow(&self) -> &$inner_ty {
919                &self.inner
920            }
921        }
922    };
923    // ================ Impl `Borrow` trait for the wrapper type. ================
924
925    // ================ Impl `BorrowMut` trait for the wrapper type. ================
926    (
927        @INTERNAL WRAPPER_IMPL_BORROW_MUT <$target:ty>
928        $(#[$meta:meta])*
929        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
930    ) => {
931        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$target> for $name$(<$($lt),+>)? {
932            fn borrow_mut(&mut self) -> &mut $target {
933                &mut self.inner
934            }
935        }
936    };
937    (
938        @INTERNAL WRAPPER_IMPL_BORROW_MUT <$target:ty>
939        $(#[$meta:meta])*
940        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
941            $(#[$field_inner_meta:meta])*
942            $inner_vis:vis inner: $inner_ty:ty
943            $(
944                ,
945                $(#[$field_meta:meta])*
946                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
947            )*
948            $(,)?
949        }
950    ) => {
951        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$target> for $name$(<$($lt),+>)? {
952            fn borrow_mut(&mut self) -> &mut $target {
953                &mut self.inner
954            }
955        }
956    };
957    (
958        @INTERNAL WRAPPER_IMPL_BORROW_MUT
959        $(#[$meta:meta])*
960        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
961    ) => {
962        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$inner_ty> for $name$(<$($lt),+>)? {
963            fn borrow_mut(&mut self) -> &mut $inner_ty {
964                &mut self.inner
965            }
966        }
967    };
968    (
969        @INTERNAL WRAPPER_IMPL_BORROW_MUT
970        $(#[$meta:meta])*
971        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
972            $(#[$field_inner_meta:meta])*
973            $inner_vis:vis inner: $inner_ty:ty
974            $(
975                ,
976                $(#[$field_meta:meta])*
977                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
978            )*
979            $(,)?
980        }
981    ) => {
982        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$inner_ty> for $name$(<$($lt),+>)? {
983            fn borrow_mut(&mut self) -> &mut $inner_ty {
984                &mut self.inner
985            }
986        }
987    };
988    // ================ Impl `Borrow` trait for the wrapper type. ================
989
990    // ================ Impl `Debug` trait for the wrapper type. ================
991    (
992        @INTERNAL WRAPPER_IMPL_DEBUG
993        $(#[$meta:meta])*
994        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
995    ) => {
996        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)?
997        where
998            $inner_ty: ::core::fmt::Debug,
999        {
1000            fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1001                self.inner.fmt(f)
1002            }
1003        }
1004    };
1005    (
1006        @INTERNAL WRAPPER_IMPL_DEBUG
1007        $(#[$meta:meta])*
1008        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1009            $(#[$field_inner_meta:meta])*
1010            $inner_vis:vis inner: $inner_ty:ty
1011            $(
1012                ,
1013                $(#[$field_meta:meta])*
1014                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1015            )*
1016            $(,)?
1017        }
1018    ) => {
1019        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)?
1020        where
1021            $inner_ty: ::core::fmt::Debug,
1022        {
1023            fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1024                self.inner.fmt(f)
1025            }
1026        }
1027    };
1028    // ================ Impl `Debug` trait for the wrapper type. ================
1029
1030    // ================ Impl `DebugName` trait for the wrapper type. ================
1031    (
1032        @INTERNAL WRAPPER_IMPL_DEBUG_NAME
1033        $(#[$meta:meta])*
1034        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
1035    ) => {
1036        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)? {
1037            fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1038                f.debug_struct(stringify!($name)).finish()
1039            }
1040        }
1041    };
1042    (
1043        @INTERNAL WRAPPER_IMPL_DEBUG_NAME
1044        $(#[$meta:meta])*
1045        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1046            $(#[$field_inner_meta:meta])*
1047            $inner_vis:vis inner: $inner_ty:ty
1048            $(
1049                ,
1050                $(#[$field_meta:meta])*
1051                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1052            )*
1053            $(,)?
1054        }
1055    ) => {
1056        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)? {
1057            fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1058                f.debug_struct(stringify!($name)).finish()
1059            }
1060        }
1061    };
1062    // ================ Impl `DebugName` trait for the wrapper type. ================
1063
1064    // ================ Impl `Deref` trait for the wrapper type. ================
1065    (
1066        @INTERNAL WRAPPER_IMPL_DEREF <$target:ty>
1067        $(#[$meta:meta])*
1068        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
1069    ) => {
1070        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1071            type Target = $target;
1072
1073            fn deref(&self) -> &Self::Target {
1074                &self.inner
1075            }
1076        }
1077    };
1078    (
1079        @INTERNAL WRAPPER_IMPL_DEREF <$target:ty>
1080        $(#[$meta:meta])*
1081        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1082            $(#[$field_inner_meta:meta])*
1083            $inner_vis:vis inner: $inner_ty:ty
1084            $(
1085                ,
1086                $(#[$field_meta:meta])*
1087                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1088            )*
1089            $(,)?
1090        }
1091    ) => {
1092        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1093            type Target = $target;
1094
1095            fn deref(&self) -> &Self::Target {
1096                &self.inner
1097            }
1098        }
1099    };
1100    (
1101        @INTERNAL WRAPPER_IMPL_DEREF
1102        $(#[$meta:meta])*
1103        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
1104    ) => {
1105        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1106            type Target = $inner_ty;
1107
1108            fn deref(&self) -> &Self::Target {
1109                &self.inner
1110            }
1111        }
1112    };
1113    (
1114        @INTERNAL WRAPPER_IMPL_DEREF
1115        $(#[$meta:meta])*
1116        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1117            $(#[$field_inner_meta:meta])*
1118            $inner_vis:vis inner: $inner_ty:ty
1119            $(
1120                ,
1121                $(#[$field_meta:meta])*
1122                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1123            )*
1124            $(,)?
1125        }
1126    ) => {
1127        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1128            type Target = $inner_ty;
1129
1130            fn deref(&self) -> &Self::Target {
1131                &self.inner
1132            }
1133        }
1134    };
1135    // ================ Impl `Deref` trait for the wrapper type. ================
1136
1137    // ================ Impl `DerefMut` traits for the wrapper type. ================
1138    (
1139        @INTERNAL WRAPPER_IMPL_DEREF_MUT <$target:ty>
1140        $(#[$meta:meta])*
1141        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
1142    ) => {
1143        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1144            fn deref_mut(&mut self) -> &mut Self::Target {
1145                &mut self.inner
1146            }
1147        }
1148    };
1149    (
1150        @INTERNAL WRAPPER_IMPL_DEREF_MUT <$target:ty>
1151        $(#[$meta:meta])*
1152        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1153            $(#[$field_inner_meta:meta])*
1154            $inner_vis:vis inner: $inner_ty:ty
1155            $(
1156                ,
1157                $(#[$field_meta:meta])*
1158                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1159            )*
1160            $(,)?
1161        }
1162    ) => {
1163        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1164            fn deref_mut(&mut self) -> &mut Self::Target {
1165                &mut self.inner
1166            }
1167        }
1168    };
1169    (
1170        @INTERNAL WRAPPER_IMPL_DEREF_MUT
1171        $(#[$meta:meta])*
1172        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
1173    ) => {
1174        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1175            fn deref_mut(&mut self) -> &mut Self::Target {
1176                &mut self.inner
1177            }
1178        }
1179    };
1180    (
1181        @INTERNAL WRAPPER_IMPL_DEREF_MUT
1182        $(#[$meta:meta])*
1183        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1184            $(#[$field_inner_meta:meta])*
1185            $inner_vis:vis inner: $inner_ty:ty
1186            $(
1187                ,
1188                $(#[$field_meta:meta])*
1189                $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1190            )*
1191            $(,)?
1192        }
1193    ) => {
1194        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1195            fn deref_mut(&mut self) -> &mut Self::Target {
1196                &mut self.inner
1197            }
1198        }
1199    };
1200    // ================ Impl `DerefMut` traits for the wrapper type. ================
1201
1202    // ================ Impl `From` trait for the wrapper type. ================
1203    (
1204        @INTERNAL WRAPPER_IMPL_FROM
1205        $(#[$meta:meta])*
1206        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner_ty:ty);
1207    ) => {
1208        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::From<$inner_ty> for $name$(<$($lt),+>)? {
1209            fn from(inner: $inner_ty) -> Self {
1210                Self::const_from(inner)
1211            }
1212        }
1213
1214        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1215            /// Creates a new instance of the wrapper type from the inner value.
1216            #[allow(unreachable_pub)]
1217            #[inline(always)]
1218            pub const fn from(inner: $inner_ty) -> Self {
1219                Self::const_from(inner)
1220            }
1221        }
1222    };
1223    (
1224        @INTERNAL WRAPPER_IMPL_FROM
1225        $(#[$meta:meta])*
1226        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1227            $(#[$field_inner_meta:meta])*
1228            $inner_vis:vis inner: $inner_ty:ty
1229            $(
1230                ,
1231                $(#[$field_meta:meta])*
1232                $field_vis:vis $field:ident: $field_ty:ty = $field_default:expr
1233            )*
1234            $(,)?
1235        }
1236    ) => {
1237        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::From<$inner_ty> for $name$(<$($lt),+>)? {
1238            fn from(inner: $inner_ty) -> Self {
1239                Self::const_from(inner)
1240            }
1241        }
1242
1243        impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1244            /// Creates a new instance of the wrapper type from the inner value.
1245            #[allow(unreachable_pub)]
1246            #[inline(always)]
1247            pub const fn from(inner: $inner_ty) -> Self {
1248                Self::const_from(inner)
1249            }
1250        }
1251    };
1252    (
1253        @INTERNAL WRAPPER_IMPL_FROM
1254        $(#[$meta:meta])*
1255        $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? {
1256            $(#[$field_inner_meta:meta])*
1257            $inner_vis:vis inner: $inner_ty:ty
1258            $(
1259                ,
1260                $(#[$field_meta:meta])*
1261                $field_vis:vis $field:ident: $field_ty:ty
1262            )*
1263            $(,)?
1264        }
1265    ) => {
1266        compile_error!(
1267            "Invalid usage of `wrapper!` macro, cannot implement \
1268            `From` trait for wrapper types with multiple fields\
1269            but no default values given."
1270        );
1271    };
1272    // ================ Impl `From` trait for the wrapper type. ================
1273
1274    // No other wrapper_impl meta
1275    (@INTERNAL WRAPPER_IMPL $($tt:tt)*) => {};
1276
1277    // Catch-all for invalid usage of the macro.
1278    (@INTERNAL $($tt:tt)*) => {
1279        compile_error!(
1280            "Invalid usage of `wrapper!` macro. @INTERNAL \
1281            Please refer to the documentation for the correct syntax."
1282        );
1283    };
1284
1285    // Core macro for the wrapper type.
1286    ($($tt:tt)*) => {
1287        $crate::wrapper!(@INTERNAL IMPL $($tt)*);
1288        $crate::wrapper!(@INTERNAL WRAPPER_IMPL $($tt)*);
1289    };
1290}