#![cfg_attr(not(feature = "std"), no_std)]
mod std_unstable;
#[doc(hidden)]
#[macro_export]
macro_rules! newtype_as_item {
($i:item) => {$i};
}
#[doc(hidden)]
#[macro_export]
macro_rules! newtype_wrap_bin_op {
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple,
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$name> for $name {
type Output = $name;
fn $meth(self, rhs: Self) -> $name {
$name((self.0).$meth(rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple,
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$name> for $name {
type Output = $name;
fn $meth(self, rhs: Self) -> $name {
$name((self.0).$meth(rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple_ref,
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<&'a $name> for &'a $name {
type Output = $name;
fn $meth(self, rhs: Self) -> $name {
$name((self.0).$meth(rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple_ref,
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<&'a $name> for &'a $name {
type Output = $name;
fn $meth(self, rhs: Self) -> $name {
$name((self.0).$meth(rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs_rewrap(&Self),
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<&'a $name> for $name {
type Output = $name;
fn $meth(self, rhs: &'a $name) -> $name {
$name((self.0).$meth(&rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs_rewrap(&Self),
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<&'a $name> for $name {
type Output = $name;
fn $meth(self, rhs: &'a $name) -> $name {
$name((self.0).$meth(&rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs_rewrap($rhs:ty),
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$rhs> for $name {
type Output = $name;
fn $meth(self, rhs: $rhs) -> $name {
$name((self.0).$meth(rhs))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs_rewrap($rhs:ty),
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$rhs> for $name {
type Output = $name;
fn $meth(self, rhs: $rhs) -> $name {
$name((self.0).$meth(rhs))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: ref_rhs_rewrap(Self),
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<$name> for &'a $name {
type Output = $name;
fn $meth(self, rhs: $name) -> $name {
$name((self.0).$meth(rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: ref_rhs_rewrap(Self),
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<$name> for &'a $name {
type Output = $name;
fn $meth(self, rhs: $name) -> $name {
$name((self.0).$meth(rhs.0))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: ref_rhs_rewrap($rhs:ty),
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<$rhs> for &'a $name {
type Output = $name;
fn $meth(self, rhs: $rhs) -> $name {
$name((self.0).$meth(rhs))
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: ref_rhs_rewrap($rhs:ty),
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<$rhs> for &'a $name {
type Output = $name;
fn $meth(self, rhs: $rhs) -> $name {
$name((self.0).$meth(rhs))
}
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! newtype_wrap_bin_op_assign {
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple,
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$name> for $name {
fn $meth(&mut self, rhs: Self) {
(self.0).$meth(rhs.0)
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple,
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$name> for $name {
fn $meth(&mut self, rhs: Self) {
(self.0).$meth(rhs.0)
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs(&Self),
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<&'a $name> for $name {
fn $meth(&mut self, rhs: &'a $name) {
(self.0).$meth(rhs.0)
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs(&Self),
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)*<&'a $name> for $name {
fn $meth(&mut self, rhs: &'a $name) {
(self.0).$meth(rhs.0)
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs($rhs:ty),
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$rhs> for $name {
fn $meth(&mut self, rhs: $rhs) {
(self.0).$meth(rhs)
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: rhs($rhs:ty),
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl $($tr)*<$rhs> for $name {
fn $meth(&mut self, rhs: $rhs) {
(self.0).$meth(rhs)
}
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! newtype_wrap_un_op {
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple,
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl $($tr)* for $name {
type Output = $name;
fn $meth(self) -> $name {
$name((self.0).$meth())
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple,
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl $($tr)* for $name {
type Output = $name;
fn $meth(self) -> $name {
$name((self.0).$meth())
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple_ref,
item: $(pub)* struct $name:ident(pub $t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)* for &'a $name {
type Output = $name;
fn $meth(self) -> $name {
$name((self.0).$meth())
}
}
}
};
(
trait: ($($tr:tt)*)::$meth:ident,
kind: simple_ref,
item: $(pub)* struct $name:ident($t:ty);
) => {
newtype_as_item! {
impl<'a> $($tr)* for &'a $name {
type Output = $name;
fn $meth(self) -> $name {
$name((self.0).$meth())
}
}
}
};
}
#[macro_export]
macro_rules! NewtypeAdd {
((*) $($tts:tt)*) => {
NewtypeAdd! { () $($tts)* }
NewtypeAdd! { (&self) $($tts)* }
NewtypeAdd! { (&Self) $($tts)* }
NewtypeAdd! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Add)::add, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Add)::add, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Add)::add, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Add)::add, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeAddAssign {
((*) $($tts:tt)*) => {
NewtypeAddAssign! { () $($tts)* }
NewtypeAddAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::AddAssign)::add_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::AddAssign)::add_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeBitAnd {
((*) $($tts:tt)*) => {
NewtypeBitAnd! { () $($tts)* }
NewtypeBitAnd! { (&self) $($tts)* }
NewtypeBitAnd! { (&Self) $($tts)* }
NewtypeBitAnd! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitAnd)::bitand, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitAnd)::bitand, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitAnd)::bitand, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitAnd)::bitand, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeBitAndAssign {
((*) $($tts:tt)*) => {
NewtypeBitAndAssign! { () $($tts)* }
NewtypeBitAndAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::BitAndAssign)::bitand_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::BitAndAssign)::bitand_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeBitOr {
((*) $($tts:tt)*) => {
NewtypeBitOr! { () $($tts)* }
NewtypeBitOr! { (&self) $($tts)* }
NewtypeBitOr! { (&Self) $($tts)* }
NewtypeBitOr! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitOr)::bitor, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitOr)::bitor, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitOr)::bitor, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitOr)::bitor, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeBitOrAssign {
((*) $($tts:tt)*) => {
NewtypeBitOrAssign! { () $($tts)* }
NewtypeBitOrAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::BitOrAssign)::bitor_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::BitOrAssign)::bitor_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeBitXor {
((*) $($tts:tt)*) => {
NewtypeBitXor! { () $($tts)* }
NewtypeBitXor! { (&self) $($tts)* }
NewtypeBitXor! { (&Self) $($tts)* }
NewtypeBitXor! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitXor)::bitxor, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitXor)::bitxor, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitXor)::bitxor, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::BitXor)::bitxor, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeBitXorAssign {
((*) $($tts:tt)*) => {
NewtypeBitXorAssign! { () $($tts)* }
NewtypeBitXorAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::BitXorAssign)::bitxor_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::BitXorAssign)::bitxor_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeDiv {
((*) $($tts:tt)*) => {
NewtypeDiv! { () $($tts)* }
NewtypeDiv! { (&self) $($tts)* }
NewtypeDiv! { (&Self) $($tts)* }
NewtypeDiv! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Div)::div, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Div)::div, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Div)::div, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Div)::div, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeDivAssign {
((*) $($tts:tt)*) => {
NewtypeDivAssign! { () $($tts)* }
NewtypeDivAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::DivAssign)::div_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::DivAssign)::div_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeMul {
((*) $($tts:tt)*) => {
NewtypeMul! { () $($tts)* }
NewtypeMul! { (&self) $($tts)* }
NewtypeMul! { (&Self) $($tts)* }
NewtypeMul! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Mul)::mul, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Mul)::mul, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Mul)::mul, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Mul)::mul, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeMulAssign {
((*) $($tts:tt)*) => {
NewtypeMulAssign! { () $($tts)* }
NewtypeMulAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::MulAssign)::mul_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::MulAssign)::mul_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeRem {
((*) $($tts:tt)*) => {
NewtypeRem! { () $($tts)* }
NewtypeRem! { (&self) $($tts)* }
NewtypeRem! { (&Self) $($tts)* }
NewtypeRem! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Rem)::rem, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Rem)::rem, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Rem)::rem, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Rem)::rem, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeRemAssign {
((*) $($tts:tt)*) => {
NewtypeRemAssign! { () $($tts)* }
NewtypeRemAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::RemAssign)::rem_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::RemAssign)::rem_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeSub {
((*) $($tts:tt)*) => {
NewtypeSub! { () $($tts)* }
NewtypeSub! { (&self) $($tts)* }
NewtypeSub! { (&Self) $($tts)* }
NewtypeSub! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Sub)::sub, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Sub)::sub, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Sub)::sub, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Sub)::sub, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeSubAssign {
((*) $($tts:tt)*) => {
NewtypeSubAssign! { () $($tts)* }
NewtypeSubAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::SubAssign)::sub_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::SubAssign)::sub_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeShl {
((*) $($tts:tt)*) => {
NewtypeShl! { () $($tts)* }
NewtypeShl! { (&self) $($tts)* }
NewtypeShl! { (&Self) $($tts)* }
NewtypeShl! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shl)::shl, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shl)::shl, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shl)::shl, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shl)::shl, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeShlAssign {
((*) $($tts:tt)*) => {
NewtypeShlAssign! { () $($tts)* }
NewtypeShlAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::ShlAssign)::shl_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::ShlAssign)::shl_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeShr {
((*) $($tts:tt)*) => {
NewtypeShr! { () $($tts)* }
NewtypeShr! { (&self) $($tts)* }
NewtypeShr! { (&Self) $($tts)* }
NewtypeShr! { (&self, Self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shr)::shr, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shr)::shr, kind: simple_ref, item: $($tts)* }
};
((&self, $($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shr)::shr, kind: ref_rhs_rewrap($($rhs)*), item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op! { trait: (::std::ops::Shr)::shr, kind: rhs_rewrap($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
#[cfg(op_assign)]
macro_rules! NewtypeShrAssign {
((*) $($tts:tt)*) => {
NewtypeShrAssign! { () $($tts)* }
NewtypeShrAssign! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::ShrAssign)::shr_assign, kind: simple, item: $($tts)* }
};
(($($rhs:tt)*) $($tts:tt)*) => {
newtype_wrap_bin_op_assign! { trait: (::std::ops::ShrAssign)::shr_assign, kind: rhs($($rhs)*), item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeNeg {
((*) $($tts:tt)*) => {
NewtypeNeg! { () $($tts)* }
NewtypeNeg! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_un_op! { trait: (::std::ops::Neg)::neg, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_un_op! { trait: (::std::ops::Neg)::neg, kind: simple_ref, item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeNot {
((*) $($tts:tt)*) => {
NewtypeNot! { () $($tts)* }
NewtypeNot! { (&self) $($tts)* }
};
(() $($tts:tt)*) => {
newtype_wrap_un_op! { trait: (::std::ops::Not)::not, kind: simple, item: $($tts)* }
};
((&self) $($tts:tt)*) => {
newtype_wrap_un_op! { trait: (::std::ops::Not)::not, kind: simple_ref, item: $($tts)* }
};
}
#[macro_export]
macro_rules! NewtypeDeref {
(() $(pub)* struct $name:ident(pub $t0:ty);) => {
impl ::std::ops::Deref for $name {
type Target = $t0;
fn deref(&self) -> &Self::Target {
&self.0
}
}
};
(() $(pub)* struct $name:ident($t0:ty);) => {
impl ::std::ops::Deref for $name {
type Target = $t0;
fn deref(&self) -> &Self::Target {
&self.0
}
}
};
}
#[macro_export]
macro_rules! NewtypeDerefMut {
(() $(pub)* struct $name:ident(pub $t0:ty);) => {
impl ::std::ops::DerefMut for $name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
};
(() $(pub)* struct $name:ident($t0:ty);) => {
impl ::std::ops::DerefMut for $name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
};
}
#[macro_export]
macro_rules! NewtypeIndex {
(($index_ty:ty) $(pub)* struct $name:ident(pub $t0:ty);) => {
impl ::std::ops::Index<$index_ty> for $name {
type Output = <$t0 as ::std::ops::Index<$index_ty>>::Output;
fn index(&self, index: $index_ty) -> &Self::Output {
(&self.0).index(index)
}
}
};
(($index_ty:ty) $(pub)* struct $name:ident($t0:ty);) => {
impl ::std::ops::Index<$index_ty> for $name {
type Output = <$t0 as ::std::ops::Index<$index_ty>>::Output;
fn index(&self, index: $index_ty) -> &Self::Output {
(&self.0).index(index)
}
}
};
}
#[macro_export]
macro_rules! NewtypeIndexMut {
(($index_ty:ty) $(pub)* struct $name:ident(pub $t0:ty);) => {
impl ::std::ops::IndexMut<$index_ty> for $name {
fn index_mut(&mut self, index: $index_ty) -> &mut Self::Output {
(&mut self.0).index_mut(index)
}
}
};
(($index_ty:ty) $(pub)* struct $name:ident($t0:ty);) => {
impl ::std::ops::IndexMut<$index_ty> for $name {
fn index_mut(&mut self, index: $index_ty) -> &mut Self::Output {
(&mut self.0).index_mut(index)
}
}
};
}
#[macro_export]
macro_rules! NewtypeFrom {
(() $(pub)* struct $name:ident(pub $t0:ty);) => {
impl ::std::convert::From<$t0> for $name {
fn from(v: $t0) -> Self {
$name(v)
}
}
impl ::std::convert::From<$name> for $t0 {
fn from(v: $name) -> Self {
v.0
}
}
};
(() $(pub)* struct $name:ident($t0:ty);) => {
impl ::std::convert::From<$t0> for $name {
fn from(v: $t0) -> Self {
$name(v)
}
}
impl ::std::convert::From<$name> for $t0 {
fn from(v: $name) -> Self {
v.0
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! newtype_fmt {
($fmt_trait:ident, $name:ident) => {
impl ::std::fmt::$fmt_trait for $name {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
::std::fmt::$fmt_trait::fmt(&self.0, fmt)
}
}
};
}
#[macro_export]
macro_rules! NewtypeBinary {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { Binary, $name }
};
}
#[macro_export]
macro_rules! NewtypeDebug {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { Debug, $name }
};
}
#[macro_export]
macro_rules! NewtypeDisplay {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { Display, $name }
};
}
#[macro_export]
macro_rules! NewtypeLowerExp {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { LowerExp, $name }
};
}
#[macro_export]
macro_rules! NewtypeLowerHex {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { LowerHex, $name }
};
}
#[macro_export]
macro_rules! NewtypeOctal {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { Octal, $name }
};
}
#[macro_export]
macro_rules! NewtypePointer {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { Pointer, $name }
};
}
#[macro_export]
macro_rules! NewtypeUpperExp {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { UpperExp, $name }
};
}
#[macro_export]
macro_rules! NewtypeUpperHex {
(() $(pub)* struct $name:ident $_field:tt;) => {
newtype_fmt! { UpperHex, $name }
};
}