newtype_derive_2018/
lib.rs

1// Copyright (c) 2015 macro-attr contributors.
2// Copyright (c) 2021 Warlock <internalmike@gmail.com>
3//
4// Licensed under the MIT license (see LICENSE or <http://opensource.org
5// /licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
6// <http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
7// files in the project carrying such notice may not be copied, modified,
8// or distributed except according to those terms.
9
10#![deny(warnings)]
11#![doc(test(attr(deny(warnings))))]
12#![doc(test(attr(allow(unknown_lints))))]
13#![doc(test(attr(allow(dead_code))))]
14#![doc(test(attr(allow(unused_variables))))]
15#![doc(test(attr(allow(unused_macros))))]
16#![doc(test(attr(allow(non_local_definitions))))]
17
18//! This crate provides several macros for deriving implementations of various traits for "newtype"
19//! wrappers (i.e. tuple structs with a single non-zero sized element).
20//! That is, given a tuple struct with exactly one field (e.g. `struct Buckets(i32)`),
21//! (or exactly one field followed by any number of zero-sized fields)
22//! these macros will derive "obvious" implementations of traits such as
23//! `Add`, `Neg`, `Index`, `Deref`, etc.
24//!
25//! All of these macros are designed to be used with the
26//! [`macro-attr-2018`](https://crates.io/crates/macro-attr-2018) crate,
27//! though they can be used independent of it.
28//!
29//! # Example
30//!
31//! Create a simple integer wrapper with some arithmetic operators:
32//!
33//! ```rust
34//! use macro_attr_2018::macro_attr;
35//! use newtype_derive_2018::*;
36//!
37//! macro_attr! {
38//!     #[derive(NewtypeAdd!, NewtypeMul!(i32))]
39//!     pub struct Happy(pub i32);
40//! }
41//!
42//! # fn main() {
43//! // Let's add some happy little ints.
44//! let a = Happy(6);
45//! let b = Happy(7);
46//! let c = (a + b) * 3;
47//! let d: i32 = c.0;
48//! assert_eq!(d, 39);
49//! # }
50//! ```
51//!
52//! Create a "deref-transparent" wrapper around a smart pointer:
53//!
54//! ```rust
55//! use macro_attr_2018::macro_attr;
56//! use newtype_derive_2018::*;
57//!
58//! macro_attr! {
59//!     #[derive(NewtypeDeref!, NewtypeDerefMut!)]
60//!     pub struct I32Array(Vec<i32>);
61//! }
62//!
63//! # fn main() {
64//! let arr = I32Array(vec![1, 2, 3]);
65//! assert_eq!(&*arr, &[1, 2, 3]);
66//! # }
67//! ```
68//!
69//! # Overview
70//!
71//! This crate provides macros to derive implementations of the following traits for newtype structs:
72//!
73//! - binary arithmetic operators: `Add`, `BitAnd`, `BitOr`, `BitXor`, `Div`, `Mul`, `Rem`,
74//!   `Sub`, `Shl`, `Shr`, plus the corresponding `*Assign` traits.
75//! - unary arithmetic operators: `Neg`, `Not`.
76//! - other operators: `Deref`, `DerefMut`, `Index`, `IndexMut`.
77//! - formatting: `Binary`, `Debug`, `Display`, `LowerExp`, `LowerHex`, `Octal`,
78//!   `Pointer`, `UpperExp`, `UpperHex`.
79//!
80//! All of these macros are named `Newtype$Trait`.
81//!
82//! All these macros support generic newtype structs. By default, no bounds for generic
83//! parameters generated. To add constraints, add where clause to the end of macros arguments.
84//! For example:
85//!
86//! ```rust
87//! # use core::ops::{Add, Sub};
88//! # use macro_attr_2018::macro_attr;
89//! # use newtype_derive_2018::{NewtypeAdd, NewtypeSub};
90//!
91//! macro_attr! {
92//!     #[derive(NewtypeAdd!(where T: Add<Output=T>))]
93//!     #[derive(NewtypeAdd!(&self, &Self where T: Add<Output=T>))]
94//!     #[derive(NewtypeSub!(* where T: Sub<Output=T>))]
95//!     pub struct Dummy<T: Copy>(T);
96//! }
97//! ```
98//!
99//! ## Binary Arithmetic Operators
100//!
101//! Each of the binary arithmetic operators accept several deriving forms.
102//! To use `Add` on a struct `T` as an example:
103//!
104//! | Attribute                 | Generated implementation                  |
105//! |---------------------------|-------------------------------------------|
106//! | `NewtypeAdd`              | `impl Add<T, Output=T> for T`             |
107//! | `NewtypeAdd(&self)`       | `impl<'a> Add<T, Output=T> for &'a T`     |
108//! | `NewtypeAdd(U)`           | `impl Add<U, Output=T> for T`             |
109//! | `NewtypeAdd(&self, U)`    | `impl<'a> Add<U, Output=T> for &'a T`     |
110//! | `NewtypeAdd(*)`           | All four combinations of `T` and `&T`     |
111//!
112//! The `*Assign` variants accept zero or one argument only. For example:
113//!
114//! | Attribute                 | Generated implementation                  |
115//! |---------------------------|-------------------------------------------|
116//! | `NewtypeAddAssign`        | `impl AddAssign<T> for T`                 |
117//! | `NewtypeAddAssign(U)`     | `impl Add<U> for T`                       |
118//! | `NewtypeAddAssign(*)`     | Implements for `T` and `&T`.              |
119//!
120//! In all cases, the implementation unwraps the newtype (where necessary),
121//! forwards to the wrapped value's implementation, then re-wraps the result in the newtype.
122//!
123//! ## Unary Arithmetic Operators
124//!
125//! Each of the binary arithmetic operators accept several deriving forms.
126//! To use `Neg` on a struct `T` as an example:
127//!
128//! | Attribute                 | Generated implementation                  |
129//! |---------------------------|-------------------------------------------|
130//! | `NewtypeNeg`              | `impl Neg<Output=T> for T`                |
131//! | `NewtypeNeg(&self)`       | `impl<'a> Neg<Output=T> for &'a T`        |
132//! | `NewtypeNeg(*)`           | Both of the above                         |
133//!
134//! In all cases, the implementation unwraps the newtype,
135//! forwards to the wrapped value's implementation, then re-wraps the result in the newtype.
136//!
137//! ## Other Operators
138//!
139//! `NewtypeDeref` and `NewtypeDerefMut` only support the argument-less form.
140//! The call is forwarded to the wrapped value's implementation.
141//!
142//! `NewtypeIndex` and `NewtypeIndexMut` must be used as `NewtypeIndex(usize)`,
143//! where the argument is the type to use for indexing.
144//! The call is forwarded to the wrapped value's implementation.
145//!
146//! ## Formatting
147//!
148//! The deriving macros for the formatting traits in [`std::fmt`][core::fmt]
149//! forward to the wrapped value's implementation.
150//!
151//! ## Using Without `macro_attr!`
152//!
153//! Although designed to be used with
154//! [`macro_attr!`](https://docs.rs/macro-attr-2018/*/macro_attr_2018/macro.macro_attr.html),
155//! all of the macros in this crate can be used without it.
156//! The following:
157//!
158//! ```rust
159//! use macro_attr_2018::macro_attr;
160//! use newtype_derive_2018::*;
161//!
162//! macro_attr! {
163//!     #[derive(Copy, Clone, Debug, NewtypeAdd!, NewtypeAdd!(f32))]
164//!     pub struct Meters(pub f32);
165//! }
166//! #
167//! # fn main() { }
168//! ```
169//!
170//! can also be written as
171//!
172//! ```rust
173//! use newtype_derive_2018::*;
174//!
175//! #[derive(Copy, Clone, Debug)]
176//! pub struct Meters(pub f32);
177//!
178//! NewtypeAdd! { () pub struct Meters(pub f32); }
179//! NewtypeAdd! { (f32) pub struct Meters(pub f32); }
180//! #
181//! # fn main() { }
182//! ```
183
184#![no_std]
185
186#[doc(hidden)]
187pub use core::convert::From as std_convert_From;
188#[doc(hidden)]
189pub use core::fmt::Binary as std_fmt_Binary;
190#[doc(hidden)]
191pub use core::fmt::Debug as std_fmt_Debug;
192#[doc(hidden)]
193pub use core::fmt::Display as std_fmt_Display;
194#[doc(hidden)]
195pub use core::fmt::Formatter as std_fmt_Formatter;
196#[doc(hidden)]
197pub use core::fmt::LowerExp as std_fmt_LowerExp;
198#[doc(hidden)]
199pub use core::fmt::LowerHex as std_fmt_LowerHex;
200#[doc(hidden)]
201pub use core::fmt::Octal as std_fmt_Octal;
202#[doc(hidden)]
203pub use core::fmt::Pointer as std_fmt_Pointer;
204#[doc(hidden)]
205pub use core::fmt::UpperExp as std_fmt_UpperExp;
206#[doc(hidden)]
207pub use core::fmt::UpperHex as std_fmt_UpperHex;
208#[doc(hidden)]
209pub use core::fmt::Result as std_fmt_Result;
210#[doc(hidden)]
211pub use core::ops::Add as std_ops_Add;
212#[doc(hidden)]
213pub use core::ops::BitAnd as std_ops_BitAnd;
214#[doc(hidden)]
215pub use core::ops::BitOr as std_ops_BitOr;
216#[doc(hidden)]
217pub use core::ops::BitXor as std_ops_BitXor;
218#[doc(hidden)]
219pub use core::ops::Deref as std_ops_Deref;
220#[doc(hidden)]
221pub use core::ops::DerefMut as std_ops_DerefMut;
222#[doc(hidden)]
223pub use core::ops::Div as std_ops_Div;
224#[doc(hidden)]
225pub use core::ops::Index as std_ops_Index;
226#[doc(hidden)]
227pub use core::ops::IndexMut as std_ops_IndexMut;
228#[doc(hidden)]
229pub use core::ops::Mul as std_ops_Mul;
230#[doc(hidden)]
231pub use core::ops::Neg as std_ops_Neg;
232#[doc(hidden)]
233pub use core::ops::Not as std_ops_Not;
234#[doc(hidden)]
235pub use core::ops::Rem as std_ops_Rem;
236#[doc(hidden)]
237pub use core::ops::Shl as std_ops_Shl;
238#[doc(hidden)]
239pub use core::ops::Shr as std_ops_Shr;
240#[doc(hidden)]
241pub use core::ops::Sub as std_ops_Sub;
242#[doc(hidden)]
243pub use generics::concat as generics_concat;
244#[doc(hidden)]
245pub use generics::parse as generics_parse;
246
247#[doc(hidden)]
248#[macro_export]
249macro_rules! def_lt_a {
250    (
251        [] $callback:path { $($args:tt)* }
252    ) => {
253        $callback ! {
254            ['newtype_derive_a] $($args)*
255        }
256    };
257    (
258        [$a:lifetime] $callback:path { $($args:tt)* }
259    ) => {
260        $callback ! {
261            [$a] $($args)*
262        }
263    };
264}
265
266#[doc(hidden)]
267#[macro_export]
268macro_rules! def_lt_a_b {
269    (
270        [] [] $callback:path { $($args:tt)* }
271    ) => {
272        $callback ! {
273            ['newtype_derive_a] ['newtype_derive_b] $($args)*
274        }
275    };
276    (
277        [$a:lifetime] [] $callback:path { $($args:tt)* }
278    ) => {
279        $callback ! {
280            [$a] ['newtype_derive_b] $($args)*
281        }
282    };
283    (
284        [] [$b:lifetime] $callback:path { $($args:tt)* }
285    ) => {
286        $callback ! {
287            ['newtype_derive_a] [$b] $($args)*
288        }
289    };
290    (
291        [$a:lifetime] [$b:lifetime] $callback:path { $($args:tt)* }
292    ) => {
293        $callback ! {
294            [$a] [$b] $($args)*
295        }
296    };
297}
298
299#[doc(hidden)]
300#[macro_export]
301macro_rules! as_item {
302    ($i:item) => {$i};
303}
304
305#[doc(hidden)]
306#[macro_export]
307macro_rules! wrap_bin_op {
308    (
309        trait: ($($tr:tt)*)::$meth:ident,
310        kind: simple,
311        item: [$name:ident] [$($bound:tt)*] [$($body:tt)+]
312    ) => {
313        $crate::generics_parse! {
314            $crate::wrap_bin_op {
315                generics_parse_done
316                [
317                    trait: ($($tr)*)::$meth,
318                    kind: simple,
319                    item: [$name] [$($bound)*]
320                ]
321            }
322            $($body)+
323        }
324    };
325    (
326        generics_parse_done
327        [
328            trait: ($($tr:tt)*)::$meth:ident,
329            kind: simple,
330            item: [$name:ident] [$($bound:tt)*]
331        ]
332        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
333        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
334    ) => {
335        $crate::generics_concat! {
336            $crate::wrap_bin_op {
337                generics_concat_done
338                [
339                    trait: ($($tr)*)::$meth,
340                    kind: simple,
341                    item: [$name] [$t0] [$([$phantom])*]
342                ]
343            }
344            [$($g)*] [$($r)*] [$($w)*],
345            [] [] [where $($bound)*]
346        }
347    };
348    (
349        generics_concat_done
350        [
351            trait: ($($tr:tt)*)::$meth:ident,
352            kind: simple,
353            item: [$name:ident] [$t0:ty] [$([$phantom:ty])*]
354        ]
355        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
356    ) => {
357        $crate::as_item! {
358            impl $($g)* $($tr)*<$name $($r)*> for $name $($r)* $($w)* {
359                type Output = Self;
360                fn $meth(self, rhs: Self) -> Self {
361                    $name(
362                        <$t0 as $($tr)*<$t0>>::$meth(self.0, rhs.0)
363                        $(, <$phantom as $crate::std_default_Default>::default())*
364                    )
365                }
366            }
367        }
368    };
369
370    (
371        [$a:lifetime]
372        trait: ($($tr:tt)*)::$meth:ident,
373        kind: simple_ref,
374        item: [$name:ident] [$($bound:tt)*] [$($body:tt)+]
375    ) => {
376        $crate::generics_parse! {
377            $crate::wrap_bin_op {
378                generics_parse_done
379                [
380                    trait: ($($tr)*)::$meth,
381                    kind: simple_ref,
382                    item: [$a] [$name] [$($bound)*]
383                ]
384            }
385            $($body)+
386        }
387    };
388    (
389        generics_parse_done
390        [
391            trait: ($($tr:tt)*)::$meth:ident,
392            kind: simple_ref,
393            item: [$a:lifetime] [$name:ident] [$($bound:tt)*]
394        ]
395        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
396        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
397    ) => {
398        $crate::generics_concat! {
399            $crate::wrap_bin_op {
400                generics_concat_done
401                [
402                    trait: ($($tr)*)::$meth,
403                    kind: simple_ref,
404                    item: [$a] [$name] [$t0] [$([$phantom])*]
405                ]
406            }
407            [ < $a > ] [] [],
408            [$($g)*] [$($r)*] [$($w)*],
409            [] [] [where $($bound)*]
410        }
411    };
412    (
413        generics_concat_done
414        [
415            trait: ($($tr:tt)*)::$meth:ident,
416            kind: simple_ref,
417            item: [$a:lifetime] [$name:ident] [$t0:ty] [$([$phantom:ty])*]
418        ]
419        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
420    ) => {
421        $crate::as_item! {
422            impl $($g)* $($tr)*<$name $($r)*> for & $a $name $($r)* $($w)* {
423                type Output = $name $($r)*;
424                fn $meth(self, rhs: $name $($r)*) -> $name $($r)* {
425                    $name(
426                        <$t0 as $($tr)*<$t0>>::$meth(self.0, rhs.0)
427                        $(, <$phantom as $crate::std_default_Default>::default())*
428                    )
429                }
430            }
431        }
432    };
433
434    (
435        [$a:lifetime]
436        trait: ($($tr:tt)*)::$meth:ident,
437        kind: rhs_rewrap(&Self),
438        item: [$name:ident] [$($bound:tt)*] [$($body:tt)+]
439    ) => {
440        $crate::generics_parse! {
441            $crate::wrap_bin_op {
442                generics_parse_done
443                [
444                    trait: ($($tr)*)::$meth,
445                    kind: rhs_rewrap(&Self),
446                    item: [$a] [$name] [$($bound)*]
447                ]
448            }
449            $($body)+
450        }
451    };
452    (
453        generics_parse_done
454        [
455            trait: ($($tr:tt)*)::$meth:ident,
456            kind: rhs_rewrap(&Self),
457            item: [$a:lifetime] [$name:ident] [$($bound:tt)*]
458        ]
459        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
460        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
461    ) => {
462        $crate::generics_concat! {
463            $crate::wrap_bin_op {
464                generics_concat_done
465                [
466                    trait: ($($tr)*)::$meth,
467                    kind: rhs_rewrap(&Self),
468                    item: [$a] [$name] [$t0] [$([$phantom])*]
469                ]
470            }
471            [ < $a > ] [] [],
472            [$($g)*] [$($r)*] [$($w)*],
473            [] [] [where $($bound)*]
474        }
475    };
476    (
477        generics_concat_done
478        [
479            trait: ($($tr:tt)*)::$meth:ident,
480            kind: rhs_rewrap(&Self),
481            item: [$a:lifetime] [$name:ident] [$t0:ty] [$([$phantom:ty])*]
482        ]
483        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
484    ) => {
485        $crate::as_item! {
486            impl $($g)* $($tr)*<& $a $name $($r)*> for $name $($r)* $($w)* {
487                type Output = Self;
488                fn $meth(self, rhs: & $a Self) -> Self {
489                    $name(
490                        <$t0 as $($tr)*<$t0>>::$meth(self.0, rhs.0)
491                        $(, <$phantom as $crate::std_default_Default>::default())*
492                    )
493                }
494            }
495        }
496    };
497
498    (
499        trait: ($($tr:tt)*)::$meth:ident,
500        kind: rhs_rewrap($Rhs:ty),
501        item: [$name:ident] [$($lt:tt)*] [$($T:tt)*] [$($bound:tt)*] [$($body:tt)+]
502    ) => {
503        $crate::generics_parse! {
504            $crate::wrap_bin_op {
505                generics_parse_done
506                [
507                    trait: ($($tr)*)::$meth,
508                    kind: rhs_rewrap($Rhs),
509                    item: [$name] [$($lt)*] [$($T)*] [$($bound)*]
510                ]
511            }
512            $($body)+
513        }
514    };
515    (
516        generics_parse_done
517        [
518            trait: ($($tr:tt)*)::$meth:ident,
519            kind: rhs_rewrap($Rhs:ty),
520            item: [$name:ident] [$($lt:tt)*] [$($T:tt)*] [$($bound:tt)*]
521        ]
522        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
523        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
524    ) => {
525        $crate::generics_concat! {
526            $crate::wrap_bin_op {
527                generics_concat_done
528                [
529                    trait: ($($tr)*)::$meth,
530                    kind: rhs_rewrap($Rhs),
531                    item: [$name] [$t0] [$([$phantom])*]
532                ]
533            }
534            [$($lt)*] [] [],
535            [$($g)*] [$($r)*] [$($w)*],
536            [$($T)*] [] [],
537            [] [] [where $($bound)*]
538        }
539    };
540    (
541        generics_concat_done
542        [
543            trait: ($($tr:tt)*)::$meth:ident,
544            kind: rhs_rewrap($Rhs:ty),
545            item: [$name:ident] [$t0:ty] [$([$phantom:ty])*]
546        ]
547        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
548    ) => {
549        $crate::as_item! {
550            impl $($g)* $($tr)*<$Rhs> for $name $($r)* $($w)* {
551                type Output = Self;
552                fn $meth(self, rhs: $Rhs) -> Self {
553                    $name(
554                        <$t0 as $($tr)*<$Rhs>>::$meth(self.0, rhs)
555                        $(, <$phantom as $crate::std_default_Default>::default())*
556                    )
557                }
558            }
559        }
560    };
561
562    (
563        [$a:lifetime] [$b:lifetime]
564        trait: ($($tr:tt)*)::$meth:ident,
565        kind: ref_rhs_rewrap(&Self),
566        item: [$name:ident] [$($bound:tt)*] [$($body:tt)+]
567    ) => {
568        $crate::generics_parse! {
569            $crate::wrap_bin_op {
570                generics_parse_done
571                [
572                    trait: ($($tr)*)::$meth,
573                    kind: ref_rhs_rewrap(&Self),
574                    item: [$a] [$b] [$name] [$($bound)*]
575                ]
576            }
577            $($body)+
578        }
579    };
580    (
581        generics_parse_done
582        [
583            trait: ($($tr:tt)*)::$meth:ident,
584            kind: ref_rhs_rewrap(&Self),
585            item: [$a:lifetime] [$b:lifetime] [$name:ident] [$($bound:tt)*]
586        ]
587        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
588        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
589    ) => {
590        $crate::generics_concat! {
591            $crate::wrap_bin_op {
592                generics_concat_done
593                [
594                    trait: ($($tr)*)::$meth,
595                    kind: ref_rhs_rewrap(&Self),
596                    item: [$a] [$b] [$name] [$t0] [$([$phantom])*]
597                ]
598            }
599            [ < $a, $b > ] [] [],
600            [$($g)*] [$($r)*] [$($w)*],
601            [] [] [where $($bound)*]
602        }
603    };
604    (
605        generics_concat_done
606        [
607            trait: ($($tr:tt)*)::$meth:ident,
608            kind: ref_rhs_rewrap(&Self),
609            item: [$a:lifetime] [$b:lifetime] [$name:ident] [$t0:ty] [$([$phantom:ty])*]
610        ]
611        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
612    ) => {
613        $crate::as_item! {
614            impl $($g)* $($tr)*<& $b $name $($r)*> for & $a $name $($r)* $($w)* {
615                type Output = $name $($r)*;
616                fn $meth(self, rhs: & $b $name $($r)*) -> $name $($r)* {
617                    $name(
618                        <$t0 as $($tr)*<$t0>>::$meth(self.0, rhs.0)
619                        $(, <$phantom as $crate::std_default_Default>::default())*
620                    )
621                }
622            }
623        }
624    };
625
626    (
627        [$a:lifetime]
628        trait: ($($tr:tt)*)::$meth:ident,
629        kind: ref_rhs_rewrap($Rhs:ty),
630        item: [$name:ident] [$($lt:tt)*] [$($T:tt)*] [$($bound:tt)*] [$($body:tt)+]
631    ) => {
632        $crate::generics_parse! {
633            $crate::wrap_bin_op {
634                generics_parse_done
635                [
636                    trait: ($($tr)*)::$meth,
637                    kind: ref_rhs_rewrap($Rhs),
638                    item: [$a] [$name] [$($lt)*] [$($T)*] [$($bound)*]
639                ]
640            }
641            $($body)+
642        }
643    };
644    (
645        generics_parse_done
646        [
647            trait: ($($tr:tt)*)::$meth:ident,
648            kind: ref_rhs_rewrap($Rhs:ty),
649            item: [$a:lifetime] [$name:ident] [$($lt:tt)*] [$($T:tt)*] [$($bound:tt)*]
650        ]
651        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
652        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
653    ) => {
654        $crate::generics_concat! {
655            $crate::wrap_bin_op {
656                generics_concat_done
657                [
658                    trait: ($($tr)*)::$meth,
659                    kind: ref_rhs_rewrap($Rhs),
660                    item: [$a] [$name] [$t0] [$([$phantom])*]
661                ]
662            }
663            [ < $a > ] [] [],
664            [$($lt)*] [] [],
665            [$($g)*] [$($r)*] [$($w)*],
666            [$($T)*] [] [],
667            [] [] [where $($bound)*]
668        }
669    };
670    (
671        generics_concat_done
672        [
673            trait: ($($tr:tt)*)::$meth:ident,
674            kind: ref_rhs_rewrap($Rhs:ty),
675            item: [$a:lifetime] [$name:ident] [$t0:ty] [$([$phantom:ty])*]
676        ]
677        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
678    ) => {
679        $crate::as_item! {
680            impl $($g)* $($tr)*<$Rhs> for & $a $name $($r)* $($w)* {
681                type Output = $name $($r)*;
682                fn $meth(self, rhs: $Rhs) -> $name $($r)* {
683                    $name(
684                        <$t0 as $($tr)*<$Rhs>>::$meth(self.0, rhs)
685                        $(, <$phantom as $crate::std_default_Default>::default())*
686                    )
687                }
688            }
689        }
690    };
691}
692
693/// Derives [`Add`](core::ops::Add) trait implementation for newtype
694/// wrappers (i.e. tuple structs with a single non-zero sized element).
695///
696/// Accepts input in any of following forms:
697///
698/// ```ignore
699/// (
700///     *
701///     $(where $($bound:tt)*)?
702/// )
703/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
704///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
705/// );
706///
707/// ```
708///
709/// ```ignore
710/// (
711///     $(where $($bound:tt)*)?
712/// )
713/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
714///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
715/// );
716/// ```
717///
718/// ```ignore
719/// (
720///     & $($a:lifetime)? self
721///     $(where $($bound:tt)*)?
722/// )
723/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
724///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
725/// );
726/// ```
727///
728/// ```ignore
729/// (
730///     & $($a:lifetime)? self, & $($b:lifetime)? Self
731///     $(where $($bound:tt)*)?
732/// )
733/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
734///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
735/// );
736/// ```
737///
738/// ```ignore
739/// (
740///     $(<$($($T:ident),+ $(,)?)?>)?
741///     & $($a:lifetime)? self, $Rhs:ty
742///     $(where $($bound:tt)*)?
743/// )
744/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
745///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
746/// );
747/// ```
748///
749/// ```ignore
750/// (
751///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
752///     & $($a:lifetime)? self, $Rhs:ty
753///     $(where $($bound:tt)*)?
754/// )
755/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
756///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
757/// );
758/// ```
759///
760/// ```ignore
761/// (
762///     & $($a:lifetime)? Self
763///     $(where $($bound:tt)*)?
764/// )
765/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
766///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
767/// );
768/// ```
769///
770/// ```ignore
771/// (
772///     $(<$($($T:ident),+ $(,)?)?>)?
773///     $Rhs:ty
774///     $(where $($bound:tt)*)?
775/// )
776/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
777///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
778/// );
779/// ```
780///
781/// ```ignore
782/// (
783///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
784///     $Rhs:ty
785///     $(where $($bound:tt)*)?
786/// )
787/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
788///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
789/// );
790/// ```
791#[macro_export]
792macro_rules! NewtypeAdd {
793    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
794        $crate::NewtypeAdd! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
795        $crate::NewtypeAdd! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
796        $crate::NewtypeAdd! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
797        $crate::NewtypeAdd! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
798    };
799    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
800        $crate::wrap_bin_op! { trait: ($crate::std_ops_Add)::add, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
801    };
802    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
803        $crate::def_lt_a! {
804            [$($a)?]
805            $crate::wrap_bin_op { trait: ($crate::std_ops_Add)::add, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
806        }
807    };
808    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
809        $crate::def_lt_a_b! {
810            [$($a)?] [$($b)?]
811            $crate::wrap_bin_op { trait: ($crate::std_ops_Add)::add, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
812        }
813    };
814    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
815        $crate::def_lt_a! {
816            [$($a)?]
817            $crate::wrap_bin_op { trait: ($crate::std_ops_Add)::add, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
818        }
819    };
820    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
821        $crate::def_lt_a! {
822            [$($a)?]
823            $crate::wrap_bin_op { trait: ($crate::std_ops_Add)::add, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
824        }
825    };
826    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
827        $crate::def_lt_a! {
828            [$($a)?]
829            $crate::wrap_bin_op { trait: ($crate::std_ops_Add)::add, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
830        }
831    };
832    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
833        $crate::wrap_bin_op! { trait: ($crate::std_ops_Add)::add, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
834    };
835    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
836        $crate::wrap_bin_op! { trait: ($crate::std_ops_Add)::add, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
837    };
838}
839
840/// Derives [`BitAnd`](core::ops::BitAnd) trait implementation for newtype
841/// wrappers (i.e. tuple structs with a single non-zero sized element).
842///
843/// Accepts input in any of following forms:
844///
845/// ```ignore
846/// (
847///     *
848///     $(where $($bound:tt)*)?
849/// )
850/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
851///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
852/// );
853///
854/// ```
855///
856/// ```ignore
857/// (
858///     $(where $($bound:tt)*)?
859/// )
860/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
861///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
862/// );
863/// ```
864///
865/// ```ignore
866/// (
867///     & $($a:lifetime)? self
868///     $(where $($bound:tt)*)?
869/// )
870/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
871///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
872/// );
873/// ```
874///
875/// ```ignore
876/// (
877///     & $($a:lifetime)? self, & $($b:lifetime)? Self
878///     $(where $($bound:tt)*)?
879/// )
880/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
881///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
882/// );
883/// ```
884///
885/// ```ignore
886/// (
887///     $(<$($($T:ident),+ $(,)?)?>)?
888///     & $($a:lifetime)? self, $Rhs:ty
889///     $(where $($bound:tt)*)?
890/// )
891/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
892///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
893/// );
894/// ```
895///
896/// ```ignore
897/// (
898///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
899///     & $($a:lifetime)? self, $Rhs:ty
900///     $(where $($bound:tt)*)?
901/// )
902/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
903///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
904/// );
905/// ```
906///
907/// ```ignore
908/// (
909///     & $($a:lifetime)? Self
910///     $(where $($bound:tt)*)?
911/// )
912/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
913///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
914/// );
915/// ```
916///
917/// ```ignore
918/// (
919///     $(<$($($T:ident),+ $(,)?)?>)?
920///     $Rhs:ty
921///     $(where $($bound:tt)*)?
922/// )
923/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
924///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
925/// );
926/// ```
927///
928/// ```ignore
929/// (
930///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
931///     $Rhs:ty
932///     $(where $($bound:tt)*)?
933/// )
934/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
935///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
936/// );
937/// ```
938#[macro_export]
939macro_rules! NewtypeBitAnd {
940    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
941        $crate::NewtypeBitAnd! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
942        $crate::NewtypeBitAnd! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
943        $crate::NewtypeBitAnd! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
944        $crate::NewtypeBitAnd! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
945    };
946    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
947        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitAnd)::bitand, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
948    };
949    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
950        $crate::def_lt_a! {
951            [$($a)?]
952            $crate::wrap_bin_op { trait: ($crate::std_ops_BitAnd)::bitand, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
953        }
954    };
955    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
956        $crate::def_lt_a_b! {
957            [$($a)?] [$($b)?]
958            $crate::wrap_bin_op { trait: ($crate::std_ops_BitAnd)::bitand, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
959        }
960    };
961    (($(<$($($T:ident),+ $(,)?)?>)? & $a:lifetime self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
962        $crate::def_lt_a! {
963            [$($a)?]
964            $crate::wrap_bin_op { trait: ($crate::std_ops_BitAnd)::bitand, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
965        }
966    };
967    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
968        $crate::def_lt_a! {
969            [$($a)?]
970            $crate::wrap_bin_op { trait: ($crate::std_ops_BitAnd)::bitand, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
971        }
972    };
973    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
974        $crate::def_lt_a! {
975            [$($a)?]
976            $crate::wrap_bin_op { trait: ($crate::std_ops_BitAnd)::bitand, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
977        }
978    };
979    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
980        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitAnd)::bitand, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
981    };
982    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
983        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitAnd)::bitand, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
984    };
985}
986
987/// Derives [`BitOr`](core::ops::BitOr) trait implementation for newtype
988/// wrappers (i.e. tuple structs with a single non-zero sized element).
989///
990/// Accepts input in any of following forms:
991///
992/// ```ignore
993/// (
994///     *
995///     $(where $($bound:tt)*)?
996/// )
997/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
998///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
999/// );
1000///
1001/// ```
1002///
1003/// ```ignore
1004/// (
1005///     $(where $($bound:tt)*)?
1006/// )
1007/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1008///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1009/// );
1010/// ```
1011///
1012/// ```ignore
1013/// (
1014///     & $($a:lifetime)? self
1015///     $(where $($bound:tt)*)?
1016/// )
1017/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1018///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1019/// );
1020/// ```
1021///
1022/// ```ignore
1023/// (
1024///     & $($a:lifetime)? self, & $($b:lifetime)? Self
1025///     $(where $($bound:tt)*)?
1026/// )
1027/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1028///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1029/// );
1030/// ```
1031///
1032/// ```ignore
1033/// (
1034///     $(<$($($T:ident),+ $(,)?)?>)?
1035///     & $($a:lifetime)? self, $Rhs:ty
1036///     $(where $($bound:tt)*)?
1037/// )
1038/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1039///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1040/// );
1041/// ```
1042///
1043/// ```ignore
1044/// (
1045///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1046///     & $($a:lifetime)? self, $Rhs:ty
1047///     $(where $($bound:tt)*)?
1048/// )
1049/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1050///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1051/// );
1052/// ```
1053///
1054/// ```ignore
1055/// (
1056///     & $($a:lifetime)? Self
1057///     $(where $($bound:tt)*)?
1058/// )
1059/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1060///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1061/// );
1062/// ```
1063///
1064/// ```ignore
1065/// (
1066///     $(<$($($T:ident),+ $(,)?)?>)?
1067///     $Rhs:ty
1068///     $(where $($bound:tt)*)?
1069/// )
1070/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1071///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1072/// );
1073/// ```
1074///
1075/// ```ignore
1076/// (
1077///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1078///     $Rhs:ty
1079///     $(where $($bound:tt)*)?
1080/// )
1081/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1082///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1083/// );
1084/// ```
1085#[macro_export]
1086macro_rules! NewtypeBitOr {
1087    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1088        $crate::NewtypeBitOr! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
1089        $crate::NewtypeBitOr! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
1090        $crate::NewtypeBitOr! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1091        $crate::NewtypeBitOr! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1092    };
1093    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1094        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitOr)::bitor, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
1095    };
1096    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1097        $crate::def_lt_a! {
1098            [$($a)?]
1099            $crate::wrap_bin_op { trait: ($crate::std_ops_BitOr)::bitor, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
1100        }
1101    };
1102    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1103        $crate::def_lt_a_b! {
1104            [$($a)?] [$($b)?]
1105            $crate::wrap_bin_op { trait: ($crate::std_ops_BitOr)::bitor, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1106        }
1107    };
1108    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1109        $crate::def_lt_a! {
1110            [$($a)?]
1111            $crate::wrap_bin_op { trait: ($crate::std_ops_BitOr)::bitor, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1112        }
1113    };
1114    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1115        $crate::def_lt_a! {
1116            [$($a)?]
1117            $crate::wrap_bin_op { trait: ($crate::std_ops_BitOr)::bitor, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1118        }
1119    };
1120    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1121        $crate::def_lt_a! {
1122            [$($a)?]
1123            $crate::wrap_bin_op { trait: ($crate::std_ops_BitOr)::bitor, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1124        }
1125    };
1126    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1127        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitOr)::bitor, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1128    };
1129    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1130        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitOr)::bitor, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1131    };
1132}
1133
1134/// Derives [`BitXor`](core::ops::BitXor) trait implementation for newtype
1135/// wrappers (i.e. tuple structs with a single non-zero sized element).
1136///
1137/// Accepts input in any of following forms:
1138///
1139/// ```ignore
1140/// (
1141///     *
1142///     $(where $($bound:tt)*)?
1143/// )
1144/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1145///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1146/// );
1147///
1148/// ```
1149///
1150/// ```ignore
1151/// (
1152///     $(where $($bound:tt)*)?
1153/// )
1154/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1155///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1156/// );
1157/// ```
1158///
1159/// ```ignore
1160/// (
1161///     & $($a:lifetime)? self
1162///     $(where $($bound:tt)*)?
1163/// )
1164/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1165///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1166/// );
1167/// ```
1168///
1169/// ```ignore
1170/// (
1171///     & $($a:lifetime)? self, & $($b:lifetime)? Self
1172///     $(where $($bound:tt)*)?
1173/// )
1174/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1175///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1176/// );
1177/// ```
1178///
1179/// ```ignore
1180/// (
1181///     $(<$($($T:ident),+ $(,)?)?>)?
1182///     & $($a:lifetime)? self, $Rhs:ty
1183///     $(where $($bound:tt)*)?
1184/// )
1185/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1186///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1187/// );
1188/// ```
1189///
1190/// ```ignore
1191/// (
1192///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1193///     & $($a:lifetime)? self, $Rhs:ty
1194///     $(where $($bound:tt)*)?
1195/// )
1196/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1197///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1198/// );
1199/// ```
1200///
1201/// ```ignore
1202/// (
1203///     & $($a:lifetime)? Self
1204///     $(where $($bound:tt)*)?
1205/// )
1206/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1207///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1208/// );
1209/// ```
1210///
1211/// ```ignore
1212/// (
1213///     $(<$($($T:ident),+ $(,)?)?>)?
1214///     $Rhs:ty
1215///     $(where $($bound:tt)*)?
1216/// )
1217/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1218///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1219/// );
1220/// ```
1221///
1222/// ```ignore
1223/// (
1224///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1225///     $Rhs:ty
1226///     $(where $($bound:tt)*)?
1227/// )
1228/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1229///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1230/// );
1231/// ```
1232#[macro_export]
1233macro_rules! NewtypeBitXor {
1234    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1235        $crate::NewtypeBitXor! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
1236        $crate::NewtypeBitXor! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
1237        $crate::NewtypeBitXor! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1238        $crate::NewtypeBitXor! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1239    };
1240    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1241        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitXor)::bitxor, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
1242    };
1243    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1244        $crate::def_lt_a! {
1245            [$($a)?]
1246            $crate::wrap_bin_op { trait: ($crate::std_ops_BitXor)::bitxor, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
1247        }
1248    };
1249    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1250        $crate::def_lt_a_b! {
1251            [$($a)?] [$($b)?]
1252            $crate::wrap_bin_op { trait: ($crate::std_ops_BitXor)::bitxor, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1253        }
1254    };
1255    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1256        $crate::def_lt_a! {
1257            [$($a)?]
1258            $crate::wrap_bin_op { trait: ($crate::std_ops_BitXor)::bitxor, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1259        }
1260    };
1261    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1262        $crate::def_lt_a! {
1263            [$($a)?]
1264            $crate::wrap_bin_op { trait: ($crate::std_ops_BitXor)::bitxor, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1265        }
1266    };
1267    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1268        $crate::def_lt_a! {
1269            [$($a)?]
1270            $crate::wrap_bin_op { trait: ($crate::std_ops_BitXor)::bitxor, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1271        }
1272    };
1273    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1274        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitXor)::bitxor, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1275    };
1276    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1277        $crate::wrap_bin_op! { trait: ($crate::std_ops_BitXor)::bitxor, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1278    };
1279}
1280
1281/// Derives [`Div`](core::ops::Div) trait implementation for newtype
1282/// wrappers (i.e. tuple structs with a single non-zero sized element).
1283///
1284/// Accepts input in any of following forms:
1285///
1286/// ```ignore
1287/// (
1288///     *
1289///     $(where $($bound:tt)*)?
1290/// )
1291/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1292///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1293/// );
1294///
1295/// ```
1296///
1297/// ```ignore
1298/// (
1299///     $(where $($bound:tt)*)?
1300/// )
1301/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1302///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1303/// );
1304/// ```
1305///
1306/// ```ignore
1307/// (
1308///     & $($a:lifetime)? self
1309///     $(where $($bound:tt)*)?
1310/// )
1311/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1312///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1313/// );
1314/// ```
1315///
1316/// ```ignore
1317/// (
1318///     & $($a:lifetime)? self, & $($b:lifetime)? Self
1319///     $(where $($bound:tt)*)?
1320/// )
1321/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1322///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1323/// );
1324/// ```
1325///
1326/// ```ignore
1327/// (
1328///     $(<$($($T:ident),+ $(,)?)?>)?
1329///     & $($a:lifetime)? self, $Rhs:ty
1330///     $(where $($bound:tt)*)?
1331/// )
1332/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1333///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1334/// );
1335/// ```
1336///
1337/// ```ignore
1338/// (
1339///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1340///     & $($a:lifetime)? self, $Rhs:ty
1341///     $(where $($bound:tt)*)?
1342/// )
1343/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1344///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1345/// );
1346/// ```
1347///
1348/// ```ignore
1349/// (
1350///     & $($a:lifetime)? Self
1351///     $(where $($bound:tt)*)?
1352/// )
1353/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1354///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1355/// );
1356/// ```
1357///
1358/// ```ignore
1359/// (
1360///     $(<$($($T:ident),+ $(,)?)?>)?
1361///     $Rhs:ty
1362///     $(where $($bound:tt)*)?
1363/// )
1364/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1365///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1366/// );
1367/// ```
1368///
1369/// ```ignore
1370/// (
1371///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1372///     $Rhs:ty
1373///     $(where $($bound:tt)*)?
1374/// )
1375/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1376///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1377/// );
1378/// ```
1379#[macro_export]
1380macro_rules! NewtypeDiv {
1381    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1382        $crate::NewtypeDiv! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
1383        $crate::NewtypeDiv! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
1384        $crate::NewtypeDiv! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1385        $crate::NewtypeDiv! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1386    };
1387    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1388        $crate::wrap_bin_op! { trait: ($crate::std_ops_Div)::div, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
1389    };
1390    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1391        $crate::def_lt_a! {
1392            [$($a)?]
1393            $crate::wrap_bin_op { trait: ($crate::std_ops_Div)::div, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
1394        }
1395    };
1396    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1397        $crate::def_lt_a_b! {
1398            [$($a)?] [$($b)?]
1399            $crate::wrap_bin_op { trait: ($crate::std_ops_Div)::div, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1400        }
1401    };
1402    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1403        $crate::def_lt_a! {
1404            [$($a)?]
1405            $crate::wrap_bin_op { trait: ($crate::std_ops_Div)::div, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1406        }
1407    };
1408    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1409        $crate::def_lt_a! {
1410            [$($a)?]
1411            $crate::wrap_bin_op { trait: ($crate::std_ops_Div)::div, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1412        }
1413    };
1414    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1415        $crate::def_lt_a! {
1416            [$($a)?]
1417            $crate::wrap_bin_op { trait: ($crate::std_ops_Div)::div, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1418        }
1419    };
1420    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1421        $crate::wrap_bin_op! { trait: ($crate::std_ops_Div)::div, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1422    };
1423    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1424        $crate::wrap_bin_op! { trait: ($crate::std_ops_Div)::div, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1425    };
1426}
1427
1428/// Derives [`Mul`](core::ops::Mul) trait implementation for newtype
1429/// wrappers (i.e. tuple structs with a single non-zero sized element).
1430///
1431/// Accepts input in any of following forms:
1432///
1433/// ```ignore
1434/// (
1435///     *
1436///     $(where $($bound:tt)*)?
1437/// )
1438/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1439///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1440/// );
1441///
1442/// ```
1443///
1444/// ```ignore
1445/// (
1446///     $(where $($bound:tt)*)?
1447/// )
1448/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1449///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1450/// );
1451/// ```
1452///
1453/// ```ignore
1454/// (
1455///     & $($a:lifetime)? self
1456///     $(where $($bound:tt)*)?
1457/// )
1458/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1459///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1460/// );
1461/// ```
1462///
1463/// ```ignore
1464/// (
1465///     & $($a:lifetime)? self, & $($b:lifetime)? Self
1466///     $(where $($bound:tt)*)?
1467/// )
1468/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1469///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1470/// );
1471/// ```
1472///
1473/// ```ignore
1474/// (
1475///     $(<$($($T:ident),+ $(,)?)?>)?
1476///     & $($a:lifetime)? self, $Rhs:ty
1477///     $(where $($bound:tt)*)?
1478/// )
1479/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1480///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1481/// );
1482/// ```
1483///
1484/// ```ignore
1485/// (
1486///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1487///     & $($a:lifetime)? self, $Rhs:ty
1488///     $(where $($bound:tt)*)?
1489/// )
1490/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1491///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1492/// );
1493/// ```
1494///
1495/// ```ignore
1496/// (
1497///     & $($a:lifetime)? Self
1498///     $(where $($bound:tt)*)?
1499/// )
1500/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1501///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1502/// );
1503/// ```
1504///
1505/// ```ignore
1506/// (
1507///     $(<$($($T:ident),+ $(,)?)?>)?
1508///     $Rhs:ty
1509///     $(where $($bound:tt)*)?
1510/// )
1511/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1512///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1513/// );
1514/// ```
1515///
1516/// ```ignore
1517/// (
1518///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1519///     $Rhs:ty
1520///     $(where $($bound:tt)*)?
1521/// )
1522/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1523///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1524/// );
1525/// ```
1526#[macro_export]
1527macro_rules! NewtypeMul {
1528    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1529        $crate::NewtypeMul! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
1530        $crate::NewtypeMul! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
1531        $crate::NewtypeMul! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1532        $crate::NewtypeMul! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1533    };
1534    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1535        $crate::wrap_bin_op! { trait: ($crate::std_ops_Mul)::mul, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
1536    };
1537    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1538        $crate::def_lt_a! {
1539            [$($a)?]
1540            $crate::wrap_bin_op { trait: ($crate::std_ops_Mul)::mul, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
1541        }
1542    };
1543    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1544        $crate::def_lt_a_b! {
1545            [$($a)?] [$($b)?]
1546            $crate::wrap_bin_op { trait: ($crate::std_ops_Mul)::mul, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1547        }
1548    };
1549    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1550        $crate::def_lt_a! {
1551            [$($a)?]
1552            $crate::wrap_bin_op { trait: ($crate::std_ops_Mul)::mul, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1553        }
1554    };
1555    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1556        $crate::def_lt_a! {
1557            [$($a)?]
1558            $crate::wrap_bin_op { trait: ($crate::std_ops_Mul)::mul, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1559        }
1560    };
1561    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1562        $crate::def_lt_a! {
1563            [$($a)?]
1564            $crate::wrap_bin_op { trait: ($crate::std_ops_Mul)::mul, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1565        }
1566    };
1567    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1568        $crate::wrap_bin_op! { trait: ($crate::std_ops_Mul)::mul, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1569    };
1570    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1571        $crate::wrap_bin_op! { trait: ($crate::std_ops_Mul)::mul, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1572    };
1573}
1574
1575/// Derives [`Rem`](core::ops::Rem) trait implementation for newtype
1576/// wrappers (i.e. tuple structs with a single non-zero sized element).
1577///
1578/// Accepts input in any of following forms:
1579///
1580/// ```ignore
1581/// (
1582///     *
1583///     $(where $($bound:tt)*)?
1584/// )
1585/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1586///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1587/// );
1588///
1589/// ```
1590///
1591/// ```ignore
1592/// (
1593///     $(where $($bound:tt)*)?
1594/// )
1595/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1596///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1597/// );
1598/// ```
1599///
1600/// ```ignore
1601/// (
1602///     & $($a:lifetime)? self
1603///     $(where $($bound:tt)*)?
1604/// )
1605/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1606///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1607/// );
1608/// ```
1609///
1610/// ```ignore
1611/// (
1612///     & $($a:lifetime)? self, & $($b:lifetime)? Self
1613///     $(where $($bound:tt)*)?
1614/// )
1615/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1616///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1617/// );
1618/// ```
1619///
1620/// ```ignore
1621/// (
1622///     $(<$($($T:ident),+ $(,)?)?>)?
1623///     & $($a:lifetime)? self, $Rhs:ty
1624///     $(where $($bound:tt)*)?
1625/// )
1626/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1627///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1628/// );
1629/// ```
1630///
1631/// ```ignore
1632/// (
1633///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1634///     & $($a:lifetime)? self, $Rhs:ty
1635///     $(where $($bound:tt)*)?
1636/// )
1637/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1638///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1639/// );
1640/// ```
1641///
1642/// ```ignore
1643/// (
1644///     & $($a:lifetime)? Self
1645///     $(where $($bound:tt)*)?
1646/// )
1647/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1648///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1649/// );
1650/// ```
1651///
1652/// ```ignore
1653/// (
1654///     $(<$($($T:ident),+ $(,)?)?>)?
1655///     $Rhs:ty
1656///     $(where $($bound:tt)*)?
1657/// )
1658/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1659///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1660/// );
1661/// ```
1662///
1663/// ```ignore
1664/// (
1665///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1666///     $Rhs:ty
1667///     $(where $($bound:tt)*)?
1668/// )
1669/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1670///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1671/// );
1672/// ```
1673#[macro_export]
1674macro_rules! NewtypeRem {
1675    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1676        $crate::NewtypeRem! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
1677        $crate::NewtypeRem! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
1678        $crate::NewtypeRem! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1679        $crate::NewtypeRem! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1680    };
1681    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1682        $crate::wrap_bin_op! { trait: ($crate::std_ops_Rem)::rem, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
1683    };
1684    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1685        $crate::def_lt_a! {
1686            [$($a)?]
1687            $crate::wrap_bin_op { trait: ($crate::std_ops_Rem)::rem, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
1688        }
1689    };
1690    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1691        $crate::def_lt_a_b! {
1692            [$($a)?] [$($b)?]
1693            $crate::wrap_bin_op { trait: ($crate::std_ops_Rem)::rem, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1694        }
1695    };
1696    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1697        $crate::def_lt_a! {
1698            [$($a)?]
1699            $crate::wrap_bin_op { trait: ($crate::std_ops_Rem)::rem, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1700        }
1701    };
1702    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1703        $crate::def_lt_a! {
1704            [$($a)?]
1705            $crate::wrap_bin_op { trait: ($crate::std_ops_Rem)::rem, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1706        }
1707    };
1708    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1709        $crate::def_lt_a! {
1710            [$($a)?]
1711            $crate::wrap_bin_op { trait: ($crate::std_ops_Rem)::rem, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1712        }
1713    };
1714    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1715        $crate::wrap_bin_op! { trait: ($crate::std_ops_Rem)::rem, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1716    };
1717    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1718        $crate::wrap_bin_op! { trait: ($crate::std_ops_Rem)::rem, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1719    };
1720}
1721
1722/// Derives [`Sub`](core::ops::Sub) trait implementation for newtype
1723/// wrappers (i.e. tuple structs with a single non-zero sized element).
1724///
1725/// Accepts input in any of following forms:
1726///
1727/// ```ignore
1728/// (
1729///     *
1730///     $(where $($bound:tt)*)?
1731/// )
1732/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1733///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1734/// );
1735///
1736/// ```
1737///
1738/// ```ignore
1739/// (
1740///     $(where $($bound:tt)*)?
1741/// )
1742/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1743///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1744/// );
1745/// ```
1746///
1747/// ```ignore
1748/// (
1749///     & $($a:lifetime)? self
1750///     $(where $($bound:tt)*)?
1751/// )
1752/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1753///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1754/// );
1755/// ```
1756///
1757/// ```ignore
1758/// (
1759///     & $($a:lifetime)? self, & $($b:lifetime)? Self
1760///     $(where $($bound:tt)*)?
1761/// )
1762/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1763///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1764/// );
1765/// ```
1766///
1767/// ```ignore
1768/// (
1769///     $(<$($($T:ident),+ $(,)?)?>)?
1770///     & $($a:lifetime)? self, $Rhs:ty
1771///     $(where $($bound:tt)*)?
1772/// )
1773/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1774///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1775/// );
1776/// ```
1777///
1778/// ```ignore
1779/// (
1780///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1781///     & $($a:lifetime)? self, $Rhs:ty
1782///     $(where $($bound:tt)*)?
1783/// )
1784/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1785///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1786/// );
1787/// ```
1788///
1789/// ```ignore
1790/// (
1791///     & $($a:lifetime)? Self
1792///     $(where $($bound:tt)*)?
1793/// )
1794/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1795///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1796/// );
1797/// ```
1798///
1799/// ```ignore
1800/// (
1801///     $(<$($($T:ident),+ $(,)?)?>)?
1802///     $Rhs:ty
1803///     $(where $($bound:tt)*)?
1804/// )
1805/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1806///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1807/// );
1808/// ```
1809///
1810/// ```ignore
1811/// (
1812///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1813///     $Rhs:ty
1814///     $(where $($bound:tt)*)?
1815/// )
1816/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1817///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1818/// );
1819/// ```
1820#[macro_export]
1821macro_rules! NewtypeSub {
1822    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1823        $crate::NewtypeSub! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
1824        $crate::NewtypeSub! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
1825        $crate::NewtypeSub! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1826        $crate::NewtypeSub! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1827    };
1828    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1829        $crate::wrap_bin_op! { trait: ($crate::std_ops_Sub)::sub, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
1830    };
1831    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1832        $crate::def_lt_a! {
1833            [$($a)?]
1834            $crate::wrap_bin_op { trait: ($crate::std_ops_Sub)::sub, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
1835        }
1836    };
1837    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1838        $crate::def_lt_a_b! {
1839            [$($a)?] [$($b)?]
1840            $crate::wrap_bin_op { trait: ($crate::std_ops_Sub)::sub, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1841        }
1842    };
1843    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1844        $crate::def_lt_a! {
1845            [$($a)?]
1846            $crate::wrap_bin_op! { trait: ($crate::std_ops_Sub)::sub, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1847        }
1848    };
1849    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1850        $crate::def_lt_a! {
1851            [$($a)?]
1852            $crate::wrap_bin_op { trait: ($crate::std_ops_Sub)::sub, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1853        }
1854    };
1855    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1856        $crate::def_lt_a! {
1857            [$($a)?]
1858            $crate::wrap_bin_op { trait: ($crate::std_ops_Sub)::sub, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1859        }
1860    };
1861    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1862        $crate::wrap_bin_op! { trait: ($crate::std_ops_Sub)::sub, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1863    };
1864    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1865        $crate::wrap_bin_op! { trait: ($crate::std_ops_Sub)::sub, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
1866    };
1867}
1868
1869/// Derives [`Shl`](core::ops::Shl) trait implementation for newtype
1870/// wrappers (i.e. tuple structs with a single non-zero sized element).
1871///
1872/// Accepts input in any of following forms:
1873///
1874/// ```ignore
1875/// (
1876///     *
1877///     $(where $($bound:tt)*)?
1878/// )
1879/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1880///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1881/// );
1882///
1883/// ```
1884///
1885/// ```ignore
1886/// (
1887///     $(where $($bound:tt)*)?
1888/// )
1889/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1890///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1891/// );
1892/// ```
1893///
1894/// ```ignore
1895/// (
1896///     & $($a:lifetime)? self
1897///     $(where $($bound:tt)*)?
1898/// )
1899/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1900///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1901/// );
1902/// ```
1903///
1904/// ```ignore
1905/// (
1906///     & $($a:lifetime)? self, & $($b:lifetime)? Self
1907///     $(where $($bound:tt)*)?
1908/// )
1909/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1910///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1911/// );
1912/// ```
1913///
1914/// ```ignore
1915/// (
1916///     $(<$($($T:ident),+ $(,)?)?>)?
1917///     & $($a:lifetime)? self, $Rhs:ty
1918///     $(where $($bound:tt)*)?
1919/// )
1920/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1921///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1922/// );
1923/// ```
1924///
1925/// ```ignore
1926/// (
1927///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1928///     & $($a:lifetime)? self, $Rhs:ty
1929///     $(where $($bound:tt)*)?
1930/// )
1931/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1932///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1933/// );
1934/// ```
1935///
1936/// ```ignore
1937/// (
1938///     & $($a:lifetime)? Self
1939///     $(where $($bound:tt)*)?
1940/// )
1941/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1942///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1943/// );
1944/// ```
1945///
1946/// ```ignore
1947/// (
1948///     $(<$($($T:ident),+ $(,)?)?>)?
1949///     $Rhs:ty
1950///     $(where $($bound:tt)*)?
1951/// )
1952/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1953///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1954/// );
1955/// ```
1956///
1957/// ```ignore
1958/// (
1959///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
1960///     $Rhs:ty
1961///     $(where $($bound:tt)*)?
1962/// )
1963/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
1964///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
1965/// );
1966/// ```
1967#[macro_export]
1968macro_rules! NewtypeShl {
1969    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1970        $crate::NewtypeShl! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
1971        $crate::NewtypeShl! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
1972        $crate::NewtypeShl! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1973        $crate::NewtypeShl! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
1974    };
1975    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1976        $crate::wrap_bin_op! { trait: ($crate::std_ops_Shl)::shl, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
1977    };
1978    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1979        $crate::def_lt_a! {
1980            [$($a)?]
1981            $crate::wrap_bin_op { trait: ($crate::std_ops_Shl)::shl, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
1982        }
1983    };
1984    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1985        $crate::def_lt_a_b! {
1986            [$($a)?] [$($b)?]
1987            $crate::wrap_bin_op { trait: ($crate::std_ops_Shl)::shl, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
1988        }
1989    };
1990    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1991        $crate::def_lt_a! {
1992            [$($a)?]
1993            $crate::wrap_bin_op { trait: ($crate::std_ops_Shl)::shl, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
1994        }
1995    };
1996    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
1997        $crate::def_lt_a! {
1998            [$($a)?]
1999            $crate::wrap_bin_op { trait: ($crate::std_ops_Shl)::shl, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
2000        }
2001    };
2002    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2003        $crate::def_lt_a! {
2004            [$($a)?]
2005            $crate::wrap_bin_op { trait: ($crate::std_ops_Shl)::shl, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
2006        }
2007    };
2008    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2009        $crate::wrap_bin_op! { trait: ($crate::std_ops_Shl)::shl, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
2010    };
2011    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2012        $crate::wrap_bin_op! { trait: ($crate::std_ops_Shl)::shl, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
2013    };
2014}
2015
2016/// Derives [`Shr`](core::ops::Shr) trait implementation for newtype
2017/// wrappers (i.e. tuple structs with a single non-zero sized element).
2018///
2019/// Accepts input in any of following forms:
2020///
2021/// ```ignore
2022/// (
2023///     *
2024///     $(where $($bound:tt)*)?
2025/// )
2026/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2027///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2028/// );
2029///
2030/// ```
2031///
2032/// ```ignore
2033/// (
2034///     $(where $($bound:tt)*)?
2035/// )
2036/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2037///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2038/// );
2039/// ```
2040///
2041/// ```ignore
2042/// (
2043///     & $($a:lifetime)? self
2044///     $(where $($bound:tt)*)?
2045/// )
2046/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2047///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2048/// );
2049/// ```
2050///
2051/// ```ignore
2052/// (
2053///     & $($a:lifetime)? self, & $($b:lifetime)? Self
2054///     $(where $($bound:tt)*)?
2055/// )
2056/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2057///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2058/// );
2059/// ```
2060///
2061/// ```ignore
2062/// (
2063///     $(<$($($T:ident),+ $(,)?)?>)?
2064///     & $($a:lifetime)? self, $Rhs:ty
2065///     $(where $($bound:tt)*)?
2066/// )
2067/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2068///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2069/// );
2070/// ```
2071///
2072/// ```ignore
2073/// (
2074///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
2075///     & $($a:lifetime)? self, $Rhs:ty
2076///     $(where $($bound:tt)*)?
2077/// )
2078/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2079///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2080/// );
2081/// ```
2082///
2083/// ```ignore
2084/// (
2085///     & $($a:lifetime)? Self
2086///     $(where $($bound:tt)*)?
2087/// )
2088/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2089///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2090/// );
2091/// ```
2092///
2093/// ```ignore
2094/// (
2095///     $(<$($($T:ident),+ $(,)?)?>)?
2096///     $Rhs:ty
2097///     $(where $($bound:tt)*)?
2098/// )
2099/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2100///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2101/// );
2102/// ```
2103///
2104/// ```ignore
2105/// (
2106///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
2107///     $Rhs:ty
2108///     $(where $($bound:tt)*)?
2109/// )
2110/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2111///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2112/// );
2113/// ```
2114#[macro_export]
2115macro_rules! NewtypeShr {
2116    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2117        $crate::NewtypeShr! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
2118        $crate::NewtypeShr! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
2119        $crate::NewtypeShr! { (&Self $(where $($bound)*)?) $vis struct $name $($token)+ }
2120        $crate::NewtypeShr! { (&self, &Self $(where $($bound)*)?) $vis struct $name $($token)+ }
2121    };
2122    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2123        $crate::wrap_bin_op! { trait: ($crate::std_ops_Shr)::shr, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
2124    };
2125    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2126        $crate::def_lt_a! {
2127            [$($a)?]
2128            $crate::wrap_bin_op { trait: ($crate::std_ops_Shr)::shr, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
2129        }
2130    };
2131    ((& $($a:lifetime)? self, & $($b:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2132        $crate::def_lt_a_b! {
2133            [$($a)?] [$($b)?]
2134            $crate::wrap_bin_op { trait: ($crate::std_ops_Shr)::shr, kind: ref_rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
2135        }
2136    };
2137    (($(<$($($T:ident),+ $(,)?)?>)? & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2138        $crate::def_lt_a! {
2139            [$($a)?]
2140            $crate::wrap_bin_op { trait: ($crate::std_ops_Shr)::shr, kind: ref_rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
2141        }
2142    };
2143    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> & $($a:lifetime)? self, $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2144        $crate::def_lt_a! {
2145            [$($a)?]
2146            $crate::wrap_bin_op { trait: ($crate::std_ops_Shr)::shr, kind: ref_rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
2147        }
2148    };
2149    ((& $($a:lifetime)? Self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2150        $crate::def_lt_a! {
2151            [$($a)?]
2152            $crate::wrap_bin_op { trait: ($crate::std_ops_Shr)::shr, kind: rhs_rewrap(&Self), item: [$name] [$($($bound)*)?] [$($token)+] }
2153        }
2154    };
2155    (($(<$($($T:ident),+ $(,)?)?>)? $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2156        $crate::wrap_bin_op! { trait: ($crate::std_ops_Shr)::shr, kind: rhs_rewrap($Rhs), item: [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$($token)+] }
2157    };
2158    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Rhs:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2159        $crate::wrap_bin_op! { trait: ($crate::std_ops_Shr)::shr, kind: rhs_rewrap($Rhs), item: [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$($token)+] }
2160    };
2161}
2162
2163#[doc(hidden)]
2164#[macro_export]
2165macro_rules! wrap_un_op {
2166    (
2167        trait: ($($tr:tt)*)::$meth:ident,
2168        kind: simple,
2169        item: [$name:ident] [$($bound:tt)*] [$($body:tt)+]
2170    ) => {
2171        $crate::generics_parse! {
2172            $crate::wrap_un_op {
2173                generics_parse_done
2174                [
2175                    trait: ($($tr)*)::$meth,
2176                    kind: simple,
2177                    item: [$name] [$($bound)*]
2178                ]
2179            }
2180            $($body)+
2181        }
2182    };
2183    (
2184        generics_parse_done
2185        [
2186            trait: ($($tr:tt)*)::$meth:ident,
2187            kind: simple,
2188            item: [$name:ident] [$($bound:tt)*]
2189        ]
2190        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2191        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2192    ) => {
2193        $crate::generics_concat! {
2194            $crate::wrap_un_op {
2195                generics_concat_done
2196                [
2197                    trait: ($($tr)*)::$meth,
2198                    kind: simple,
2199                    item: [$name] [$t0] [$([$phantom])*]
2200                ]
2201            }
2202            [$($g)*] [$($r)*] [$($w)*],
2203            [] [] [where $($bound)*]
2204        }
2205    };
2206    (
2207        generics_concat_done
2208        [
2209            trait: ($($tr:tt)*)::$meth:ident,
2210            kind: simple,
2211            item: [$name:ident] [$t0:ty] [$([$phantom:ty])*]
2212        ]
2213        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2214    ) => {
2215        $crate::as_item! {
2216            impl $($g)* $($tr)* for $name $($r)* $($w)* {
2217                type Output = Self;
2218                fn $meth(self) -> Self {
2219                    $name(
2220                        <$t0 as $($tr)*>::$meth(self.0)
2221                        $(, <$phantom as $crate::std_default_Default>::default())*
2222                    )
2223                }
2224            }
2225        }
2226    };
2227
2228    (
2229        [$a:lifetime]
2230        trait: ($($tr:tt)*)::$meth:ident,
2231        kind: simple_ref,
2232        item: [$name:ident] [$($bound:tt)*] [$($body:tt)+]
2233    ) => {
2234        $crate::generics_parse! {
2235            $crate::wrap_un_op {
2236                generics_parse_done
2237                [
2238                    trait: ($($tr)*)::$meth,
2239                    kind: simple_ref,
2240                    item: [$a] [$name] [$($bound)*]
2241                ]
2242            }
2243            $($body)+
2244        }
2245    };
2246    (
2247        generics_parse_done
2248        [
2249            trait: ($($tr:tt)*)::$meth:ident,
2250            kind: simple_ref,
2251            item: [$a:lifetime] [$name:ident] [$($bound:tt)*]
2252        ]
2253        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2254        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2255    ) => {
2256        $crate::generics_concat! {
2257            $crate::wrap_un_op {
2258                generics_concat_done
2259                [
2260                    trait: ($($tr)*)::$meth,
2261                    kind: simple_ref,
2262                    item: [$a] [$name] [$t0] [$([$phantom])*]
2263                ]
2264            }
2265            [ < $a > ] [] [],
2266            [$($g)*] [$($r)*] [$($w)*],
2267            [] [] [where $($bound)*]
2268        }
2269    };
2270    (
2271        generics_concat_done
2272        [
2273            trait: ($($tr:tt)*)::$meth:ident,
2274            kind: simple_ref,
2275            item: [$a:lifetime] [$name:ident] [$t0:ty] [$([$phantom:ty])*]
2276        ]
2277        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2278    ) => {
2279        $crate::as_item! {
2280            impl $($g)* $($tr)* for & $a $name $($r)* $($w)* {
2281                type Output = $name $($r)*;
2282                fn $meth(self) -> $name $($r)* {
2283                    $name(
2284                        <$t0 as $($tr)*>::$meth(self.0)
2285                        $(, <$phantom as $crate::std_default_Default>::default())*
2286                    )
2287                }
2288            }
2289        }
2290    };
2291}
2292
2293/// Derives [`Neg`](core::ops::Neg) trait implementation for newtype
2294/// wrappers (i.e. tuple structs with a single non-zero sized element).
2295///
2296/// Accepts input in any of following forms:
2297///
2298/// ```ignore
2299/// (
2300///     *
2301///     $(where $($bound:tt)*)?
2302/// )
2303/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2304///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2305/// );
2306/// ```
2307///
2308/// ```ignore
2309/// (
2310///     $(where $($bound:tt)*)?
2311/// )
2312/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2313///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2314/// );
2315/// ```
2316///
2317/// ```ignore
2318/// (
2319///     & $($a:lifetime)? self
2320///     $(where $($bound:tt)*)?
2321/// )
2322/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2323///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2324/// );
2325/// ```
2326#[macro_export]
2327macro_rules! NewtypeNeg {
2328    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2329        $crate::NewtypeNeg! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
2330        $crate::NewtypeNeg! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
2331    };
2332    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2333        $crate::wrap_un_op! { trait: ($crate::std_ops_Neg)::neg, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
2334    };
2335    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2336        $crate::def_lt_a! {
2337            [$($a)?]
2338            $crate::wrap_un_op { trait: ($crate::std_ops_Neg)::neg, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
2339        }
2340    };
2341}
2342
2343/// Derives [`Not`](core::ops::Not) trait implementation for newtype
2344/// wrappers (i.e. tuple structs with a single non-zero sized element).
2345///
2346/// Accepts input in any of following forms:
2347///
2348/// ```ignore
2349/// (
2350///     *
2351///     $(where $($bound:tt)*)?
2352/// )
2353/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2354///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2355/// );
2356/// ```
2357///
2358/// ```ignore
2359/// (
2360///     $(where $($bound:tt)*)?
2361/// )
2362/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2363///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2364/// );
2365/// ```
2366///
2367/// ```ignore
2368/// (
2369///     & $($a:lifetime)? self
2370///     $(where $($bound:tt)*)?
2371/// )
2372/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2373///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2374/// );
2375/// ```
2376#[macro_export]
2377macro_rules! NewtypeNot {
2378    ((* $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2379        $crate::NewtypeNot! { ($(where $($bound)*)?) $vis struct $name $($token)+ }
2380        $crate::NewtypeNot! { (&self $(where $($bound)*)?) $vis struct $name $($token)+ }
2381    };
2382    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2383        $crate::wrap_un_op! { trait: ($crate::std_ops_Not)::not, kind: simple, item: [$name] [$($($bound)*)?] [$($token)+] }
2384    };
2385    ((& $($a:lifetime)? self $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2386        $crate::def_lt_a! {
2387            [$($a)?]
2388            $crate::wrap_un_op { trait: ($crate::std_ops_Not)::not, kind: simple_ref, item: [$name] [$($($bound)*)?] [$($token)+] }
2389        }
2390    };
2391}
2392
2393/// Derives [`Deref`](core::ops::Deref) trait implementation for newtype
2394/// wrappers (i.e. tuple structs with a single non-zero sized element).
2395///
2396/// Accepts input in the following form:
2397///
2398/// ```ignore
2399/// (
2400///     $(where $($bound:tt)*)?
2401/// )
2402/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2403///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2404/// );
2405/// ```
2406#[macro_export]
2407macro_rules! NewtypeDeref {
2408    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2409        $crate::generics_parse! {
2410            $crate::NewtypeDeref_impl {
2411                generics_parse_done
2412                [$name] [$($($bound)*)?]
2413            }
2414            $($token)+
2415        }
2416    };
2417}
2418
2419#[doc(hidden)]
2420#[macro_export]
2421macro_rules! NewtypeDeref_impl {
2422    (
2423        generics_parse_done
2424        [$name:ident] [$($bound:tt)*]
2425        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2426        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2427    ) => {
2428        $crate::generics_concat! {
2429            $crate::NewtypeDeref_impl {
2430                generics_concat_done
2431                [$name] [$t0]
2432            }
2433            [$($g)*] [$($r)*] [$($w)*],
2434            [] [] [where $($bound)*]
2435        }
2436    };
2437    (
2438        generics_concat_done
2439        [$name:ident] [$t0:ty]
2440        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2441    ) => {
2442        impl $($g)* $crate::std_ops_Deref for $name $($r)* $($w)* {
2443            type Target = <$t0 as $crate::std_ops_Deref>::Target;
2444
2445            fn deref(&self) -> &Self::Target { <$t0 as $crate::std_ops_Deref>::deref(&self.0) }
2446        }
2447    };
2448}
2449
2450/// Derives [`DerefMut`](core::ops::DerefMut) trait implementation for newtype
2451/// wrappers (i.e. tuple structs with a single non-zero sized element).
2452///
2453/// Accepts input in the following form:
2454///
2455/// ```ignore
2456/// (
2457///     $(where $($bound:tt)*)?
2458/// )
2459/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2460///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2461/// );
2462/// ```
2463#[macro_export]
2464macro_rules! NewtypeDerefMut {
2465    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2466        $crate::generics_parse! {
2467            $crate::NewtypeDerefMut_impl {
2468                generics_parse_done
2469                [$name] [$($($bound)*)?]
2470            }
2471            $($token)+
2472        }
2473    };
2474}
2475
2476#[doc(hidden)]
2477#[macro_export]
2478macro_rules! NewtypeDerefMut_impl {
2479    (
2480        generics_parse_done
2481        [$name:ident] [$($bound:tt)*]
2482        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2483        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2484    ) => {
2485        $crate::generics_concat! {
2486            $crate::NewtypeDerefMut_impl {
2487                generics_concat_done
2488                [$name] [$t0]
2489            }
2490            [$($g)*] [$($r)*] [$($w)*],
2491            [] [] [where $($bound)*]
2492        }
2493    };
2494    (
2495        generics_concat_done
2496        [$name:ident] [$t0:ty]
2497        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2498    ) => {
2499        impl $($g)* $crate::std_ops_DerefMut for $name $($r)* $($w)* {
2500            fn deref_mut(&mut self) -> &mut Self::Target { <$t0 as $crate::std_ops_DerefMut>::deref_mut(&mut self.0) }
2501        }
2502    };
2503}
2504
2505/// Derives [`From`](core::convert::From) trait implementation for newtype
2506/// wrappers (i.e. tuple structs with a single non-zero sized element).
2507///
2508/// Accepts input in the following form:
2509///
2510/// ```ignore
2511/// (
2512///     $(where $($bound:tt)*)?
2513/// )
2514/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2515///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2516/// );
2517/// ```
2518///
2519/// ```ignore
2520/// (
2521///     $(wrap where $($bound:tt)*)?
2522/// )
2523/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2524///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2525/// );
2526/// ```
2527///
2528/// ```ignore
2529/// (
2530///     $(unwrap where $($bound:tt)*)?
2531/// )
2532/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2533///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2534/// );
2535/// ```
2536#[macro_export]
2537macro_rules! NewtypeFrom {
2538    (($($mode:tt)? $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2539        $crate::generics_parse! {
2540            $crate::NewtypeFrom_impl {
2541                generics_parse_done
2542                [$($mode)?]
2543                [$name] [$($($bound)*)?]
2544            }
2545            $($token)+
2546        }
2547    };
2548}
2549
2550#[doc(hidden)]
2551#[macro_export]
2552macro_rules! NewtypeFrom_impl {
2553    (
2554        generics_parse_done
2555        [$($mode:tt)?]
2556        [$name:ident] [$($bound:tt)*]
2557        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2558        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2559    ) => {
2560        $crate::generics_concat! {
2561            $crate::NewtypeFrom_impl {
2562                generics_concat_done
2563                [$($mode)?]
2564                [$name] [$t0]
2565            }
2566            [$($g)*] [$($r)*] [$($w)*],
2567            [] [] [where $($bound)*]
2568        }
2569    };
2570    (
2571        generics_concat_done
2572        [wrap]
2573        [$name:ident] [$t0:ty]
2574        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2575    ) => {
2576        impl $($g)* $crate::std_convert_From<$t0> for $name $($r)* $($w)* {
2577            fn from(v: $t0) -> Self { Self(v) }
2578        }
2579    };
2580    (
2581        generics_concat_done
2582        [unwrap]
2583        [$name:ident] [$t0:ty]
2584        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2585    ) => {
2586        impl $($g)* $crate::std_convert_From<$name $($r)*> for $t0 $($w)* {
2587            fn from(v: $name $($r)*) -> Self { v.0 }
2588        }
2589    };
2590    (
2591        generics_concat_done
2592        []
2593        [$name:ident] [$t0:ty]
2594        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2595    ) => {
2596        $crate::NewtypeFrom_impl! {
2597            generics_concat_done
2598            [wrap]
2599            [$name] [$t0]
2600            [$($g)*] [$($r)*] [$($w)*]
2601        }
2602        $crate::NewtypeFrom_impl! {
2603            generics_concat_done
2604            [unwrap]
2605            [$name] [$t0]
2606            [$($g)*] [$($r)*] [$($w)*]
2607        }
2608    };
2609}
2610
2611/// Derives [`Index`](core::ops::Index) trait implementation for newtype
2612/// wrappers (i.e. tuple structs with a single non-zero sized element).
2613///
2614/// Accepts input in any of following forms:
2615///
2616/// ```ignore
2617/// (
2618///     $(<$($($T:ident),+ $(,)?)?>)?
2619///     $Index:ty
2620///     $(where $($bound:tt)*)?
2621/// )
2622/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2623///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2624/// );
2625/// ```
2626///
2627/// ```ignore
2628/// (
2629///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
2630///     $Index:ty
2631///     $(where $($bound:tt)*)?
2632/// )
2633/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2634///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2635/// );
2636/// ```
2637#[macro_export]
2638macro_rules! NewtypeIndex {
2639    (($(<$($($T:ident),+ $(,)?)?>)? $Index:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2640        $crate::generics_parse! {
2641            $crate::NewtypeIndex_impl {
2642                generics_parse_done
2643                [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$Index]
2644            }
2645            $($token)+
2646        }
2647    };
2648    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Index:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2649        $crate::generics_parse! {
2650            $crate::NewtypeIndex_impl {
2651                generics_parse_done
2652                [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$Index]
2653            }
2654            $($token)+
2655        }
2656    };
2657}
2658
2659#[doc(hidden)]
2660#[macro_export]
2661macro_rules! NewtypeIndex_impl {
2662    (
2663        generics_parse_done
2664        [$name:ident] [$($lt:tt)*] [$($T:tt)*] [$($bound:tt)*] [$Index:ty]
2665        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2666        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2667    ) => {
2668        $crate::generics_concat! {
2669            $crate::NewtypeIndex_impl {
2670                generics_concat_done
2671                [$name] [$Index] [$t0]
2672            }
2673            [$($lt)*] [] [],
2674            [$($g)*] [$($r)*] [$($w)*],
2675            [$($T)*] [] [],
2676            [] [] [where $($bound)*]
2677        }
2678    };
2679    (
2680        generics_concat_done
2681        [$name:ident] [$Index:ty] [$t0:ty]
2682        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2683    ) => {
2684        impl $($g)* $crate::std_ops_Index<$Index> for $name $($r)* $($w)* {
2685            type Output = <$t0 as $crate::std_ops_Index<$Index>>::Output;
2686
2687            fn index(&self, index: $Index) -> &Self::Output {
2688                <$t0 as $crate::std_ops_Index<$Index>>::index(&self.0, index)
2689            }
2690        }
2691    };
2692}
2693
2694/// Derives [`IndexMut`](core::ops::IndexMut) trait implementation for newtype
2695/// wrappers (i.e. tuple structs with a single non-zero sized element).
2696///
2697/// Accepts input in any of following forms:
2698///
2699/// ```ignore
2700/// (
2701///     $(<$($($T:ident),+ $(,)?)?>)?
2702///     $Index:ty
2703///     $(where $($bound:tt)*)?
2704/// )
2705/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2706///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2707/// );
2708/// ```
2709///
2710/// ```ignore
2711/// (
2712///     <$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?>
2713///     $Index:ty
2714///     $(where $($bound:tt)*)?
2715/// )
2716/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2717///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2718/// );
2719/// ```
2720#[macro_export]
2721macro_rules! NewtypeIndexMut {
2722    (($(<$($($T:ident),+ $(,)?)?>)? $Index:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2723        $crate::generics_parse! {
2724            $crate::NewtypeIndexMut_impl {
2725                generics_parse_done
2726                [$name] [] [ $($( < $($T),+ > )?)? ] [$($($bound)*)?] [$Index]
2727            }
2728            $($token)+
2729        }
2730    };
2731    ((<$($lt:lifetime),+ $(, $($T:ident),+)? $(,)?> $Index:ty $(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2732        $crate::generics_parse! {
2733            $crate::NewtypeIndexMut_impl {
2734                generics_parse_done
2735                [$name] [ < $($lt),+ > ] [ $( < $($T),+ > )? ] [$($($bound)*)?] [$Index]
2736            }
2737            $($token)+
2738        }
2739    };
2740}
2741
2742#[doc(hidden)]
2743#[macro_export]
2744macro_rules! NewtypeIndexMut_impl {
2745    (
2746        generics_parse_done
2747        [$name:ident] [$($lt:tt)*] [$($T:tt)*] [$($bound:tt)*] [$Index:ty]
2748        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2749        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2750    ) => {
2751        $crate::generics_concat! {
2752            $crate::NewtypeIndexMut_impl {
2753                generics_concat_done
2754                [$name] [$Index] [$t0]
2755            }
2756            [$($lt)*] [] [],
2757            [$($g)*] [$($r)*] [$($w)*],
2758            [$($T)*] [] [],
2759            [] [] [where $($bound)*]
2760        }
2761    };
2762    (
2763        generics_concat_done
2764        [$name:ident] [$Index:ty] [$t0:ty]
2765        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2766    ) => {
2767        impl $($g)* $crate::std_ops_IndexMut<$Index> for $name $($r)* $($w)* {
2768            fn index_mut(&mut self, index: $Index) -> &mut Self::Output {
2769                <$t0 as $crate::std_ops_IndexMut<$Index>>::index_mut(&mut self.0, index)
2770            }
2771        }
2772    };
2773}
2774
2775#[doc(hidden)]
2776#[macro_export]
2777macro_rules! wrap_fmt {
2778    ([$tr:path] [$name:ident] [$($bound:tt)*] [$($body:tt)+]) => {
2779        $crate::generics_parse! {
2780            $crate::wrap_fmt {
2781                generics_parse_done
2782                [$tr] [$name] [$($bound)*]
2783            }
2784            $($body)+
2785        }
2786    };
2787    (
2788        generics_parse_done
2789        [$tr:path] [$name:ident] [$($bound:tt)*]
2790        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2791        ($(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?);
2792    ) => {
2793        $crate::generics_concat! {
2794            $crate::wrap_fmt {
2795                generics_concat_done
2796                [$tr] [$name] [$t0]
2797            }
2798            [$($g)*] [$($r)*] [$($w)*],
2799            [] [] [where $($bound)*]
2800        }
2801    };
2802    (
2803        generics_concat_done
2804        [$tr:path] [$name:ident] [$t0:ty]
2805        [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
2806    ) => {
2807        impl $($g)* $tr for $name $($r)* $($w)* {
2808            fn fmt(&self, f: &mut $crate::std_fmt_Formatter) -> $crate::std_fmt_Result {
2809                <$t0 as $tr>::fmt(&self.0, f)
2810            }
2811        }
2812    };
2813}
2814
2815/// Derives [`Binary`](core::fmt::Binary) trait implementation for newtype
2816/// wrappers (i.e. tuple structs with a single non-zero sized element).
2817///
2818/// Accepts input in the following form:
2819///
2820/// ```ignore
2821/// ($(where $($bound:tt)*)?)
2822/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2823///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2824/// );
2825/// ```
2826#[macro_export]
2827macro_rules! NewtypeBinary {
2828    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2829        $crate::wrap_fmt! { [$crate::std_fmt_Binary] [$name] [$($($bound)*)?] [$($token)+] }
2830    };
2831}
2832
2833/// Derives [`Debug`](core::fmt::Debug) trait implementation for newtype
2834/// wrappers (i.e. tuple structs with a single non-zero sized element).
2835///
2836/// Accepts input in the following form:
2837///
2838/// ```ignore
2839/// ($(where $($bound:tt)*)?)
2840/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2841///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2842/// );
2843/// ```
2844#[macro_export]
2845macro_rules! NewtypeDebug {
2846    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2847        $crate::wrap_fmt! { [$crate::std_fmt_Debug] [$name] [$($($bound)*)?] [$($token)+] }
2848    };
2849}
2850
2851/// Derives [`Display`](core::fmt::Display) trait implementation for newtype
2852/// wrappers (i.e. tuple structs with a single non-zero sized element).
2853///
2854/// Accepts input in the following form:
2855///
2856/// ```ignore
2857/// ($(where $($bound:tt)*)?)
2858/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2859///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2860/// );
2861/// ```
2862#[macro_export]
2863macro_rules! NewtypeDisplay {
2864    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2865        $crate::wrap_fmt! { [$crate::std_fmt_Display] [$name] [$($($bound)*)?] [$($token)+] }
2866    };
2867}
2868
2869/// Derives [`LowerExp`](core::fmt::LowerExp) trait implementation for newtype
2870/// wrappers (i.e. tuple structs with a single non-zero sized element).
2871///
2872/// Accepts input in the following form:
2873///
2874/// ```ignore
2875/// ($(where $($bound:tt)*)?)
2876/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2877///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2878/// );
2879/// ```
2880#[macro_export]
2881macro_rules! NewtypeLowerExp {
2882    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2883        $crate::wrap_fmt! { [$crate::std_fmt_LowerExp] [$name] [$($($bound)*)?] [$($token)+] }
2884    };
2885}
2886
2887/// Derives [`LowerHex`](core::fmt::LowerHex) trait implementation for newtype
2888/// wrappers (i.e. tuple structs with a single non-zero sized element).
2889///
2890/// Accepts input in the following form:
2891///
2892/// ```ignore
2893/// ($(where $($bound:tt)*)?)
2894/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2895///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2896/// );
2897/// ```
2898#[macro_export]
2899macro_rules! NewtypeLowerHex {
2900    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2901        $crate::wrap_fmt! { [$crate::std_fmt_LowerHex] [$name] [$($($bound)*)?] [$($token)+] }
2902    };
2903}
2904
2905/// Derives [`Octal`](core::fmt::Octal) trait implementation for newtype
2906/// wrappers (i.e. tuple structs with a single non-zero sized element).
2907///
2908/// Accepts input in the following form:
2909///
2910/// ```ignore
2911/// ($(where $($bound:tt)*)?)
2912/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2913///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2914/// );
2915/// ```
2916#[macro_export]
2917macro_rules! NewtypeOctal {
2918    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2919        $crate::wrap_fmt! { [$crate::std_fmt_Octal] [$name] [$($($bound)*)?] [$($token)+] }
2920    };
2921}
2922
2923/// Derives [`Pointer`](core::fmt::Pointer) trait implementation for newtype
2924/// wrappers (i.e. tuple structs with a single non-zero sized element).
2925///
2926/// Accepts input in the following form:
2927///
2928/// ```ignore
2929/// ($(where $($bound:tt)*)?)
2930/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2931///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2932/// );
2933/// ```
2934#[macro_export]
2935macro_rules! NewtypePointer {
2936    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2937        $crate::wrap_fmt! { [$crate::std_fmt_Pointer] [$name] [$($($bound)*)?] [$($token)+] }
2938    };
2939}
2940
2941/// Derives [`UpperExp`](core::fmt::UpperExp) trait implementation for newtype
2942/// wrappers (i.e. tuple structs with a single non-zero sized element).
2943///
2944/// Accepts input in the following form:
2945///
2946/// ```ignore
2947/// ($(where $($bound:tt)*)?)
2948/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2949///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2950/// );
2951/// ```
2952#[macro_export]
2953macro_rules! NewtypeUpperExp {
2954    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2955        $crate::wrap_fmt! { [$crate::std_fmt_UpperExp] [$name] [$($($bound)*)?] [$($token)+] }
2956    };
2957}
2958
2959/// Derives [`UpperHex`](core::fmt::UpperHex) trait implementation for newtype
2960/// wrappers (i.e. tuple structs with a single non-zero sized element).
2961///
2962/// Accepts input in the following form:
2963///
2964/// ```ignore
2965/// ($(where $($bound:tt)*)?)
2966/// $vis:vis struct $name:ident $(<$generics> $(where $where_clause)?)? (
2967///     $(pub)? $t0:ty $(, $(pub)? $phantom:ty)* $(,)?
2968/// );
2969/// ```
2970#[macro_export]
2971macro_rules! NewtypeUpperHex {
2972    (($(where $($bound:tt)*)?) $vis:vis struct $name:ident $($token:tt)+) => {
2973        $crate::wrap_fmt! { [$crate::std_fmt_UpperHex] [$name] [$($($bound)*)?] [$($token)+] }
2974    };
2975}