#[macro_export]
macro_rules! impl_std_traits_for_owned_slice {
(
Std {
core: $core:ident,
alloc: $alloc:ident,
};
Spec {
spec: $spec:ty,
custom: $custom:ty,
inner: $inner:ty,
error: $error:ty,
slice_custom: $slice_custom:ty,
slice_inner: $slice_inner:ty,
slice_error: $slice_error:ty,
};
$({$($rest:tt)*});* $(;)?
) => {
$(
$crate::impl_std_traits_for_owned_slice! {
@impl; ({$core, $alloc}, $spec, $custom, $inner, $error,
<$spec as $crate::OwnedSliceSpec>::SliceSpec, $slice_custom, $slice_inner,
$slice_error);
rest=[$($rest)*];
}
)*
};
(
Spec {
spec: $spec:ty,
custom: $custom:ty,
inner: $inner:ty,
error: $error:ty,
slice_custom: $slice_custom:ty,
slice_inner: $slice_inner:ty,
slice_error: $slice_error:ty,
};
$({$($rest:tt)*});* $(;)?
) => {
$(
$crate::impl_std_traits_for_owned_slice! {
@impl; ({std, std}, $spec, $custom, $inner, $error,
<$spec as $crate::OwnedSliceSpec>::SliceSpec, $slice_custom, $slice_inner,
$slice_error);
rest=[$($rest)*];
}
)*
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ Borrow<{SliceCustom}> ];
) => {
impl $core::borrow::Borrow<$slice_custom> for $custom {
#[inline]
fn borrow(&self) -> &$slice_custom {
unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ Borrow<$param:ty> ];
) => {
impl $core::borrow::Borrow<$param> for $custom
where
$slice_inner: $core::borrow::Borrow<$param>,
{
#[inline]
fn borrow(&self) -> &$param {
<$spec as $crate::OwnedSliceSpec>::as_slice_inner(self).borrow()
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ BorrowMut<{SliceCustom}> ];
) => {
impl $core::borrow::BorrowMut<$slice_custom> for $custom {
#[inline]
fn borrow_mut(&mut self) -> &mut $slice_custom {
unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_mut_slice, $spec, $slice_spec, self)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ BorrowMut<$param:ty> ];
) => {
impl $core::borrow::BorrowMut<$param> for $custom
where
$slice_inner: $core::borrow::BorrowMut<$param>,
{
#[inline]
fn borrow_mut(&mut self) -> &mut $param {
<$spec as $crate::OwnedSliceSpec>::as_slice_inner_mut(self).borrow_mut()
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ ToOwned<Owned = {Custom}> for {SliceCustom} ];
) => {
impl $alloc::borrow::ToOwned for $slice_custom
where
for<'a> $inner: From<&'a $slice_inner>,
{
type Owned = $custom;
fn to_owned(&self) -> Self::Owned {
let inner = <$inner>::from(<$slice_spec as $crate::SliceSpec>::as_inner(self));
unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ AsMut<{SliceCustom}> ];
) => {
impl $core::convert::AsMut<$slice_custom> for $custom {
#[inline]
fn as_mut(&mut self) -> &mut $slice_custom {
unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_mut_slice, $spec, $slice_spec, self)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ AsMut<$param:ty> ];
) => {
impl $core::convert::AsMut<$param> for $custom
where
$slice_inner: $core::convert::AsMut<$param>,
{
#[inline]
fn as_mut(&self) -> &$param {
<$spec as $crate::OwnedSliceSpec>::as_slice_inner_mut(self).as_mut()
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ AsRef<{SliceCustom}> ];
) => {
impl $core::convert::AsRef<$slice_custom> for $custom {
#[inline]
fn as_ref(&self) -> &$slice_custom {
unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ AsRef<$param:ty> ];
) => {
impl $core::convert::AsRef<$param> for $custom
where
$slice_inner: $core::convert::AsRef<$param>,
{
#[inline]
fn as_ref(&self) -> &$param {
<$spec as $crate::OwnedSliceSpec>::as_slice_inner(self).as_ref()
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ From<&{SliceInner}> ];
) => {
impl<'a> $core::convert::From<&'a $slice_inner> for $custom
where
$inner: From<&'a $slice_inner>,
{
fn from(s: &'a $slice_inner) -> Self {
assert!(
<$slice_spec as $crate::SliceSpec>::validate(s).is_ok(),
"Attempt to convert invalid data: `From<&{}> for {}`",
stringify!($slice_inner), stringify!($custom)
);
let inner = <$inner>::from(s);
unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ From<&{SliceCustom}> ];
) => {
impl<'a> $core::convert::From<&'a $slice_custom> for $custom
where
$inner: From<&'a $slice_inner>,
{
fn from(s: &'a $slice_custom) -> Self {
let inner = <$inner>::from(<$slice_spec as $crate::SliceSpec>::as_inner(s));
unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ From<{Inner}> ];
) => {
impl $core::convert::From<$inner> for $custom {
fn from(inner: $inner) -> Self {
assert!(
<$slice_spec as $crate::SliceSpec>::validate(
<$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(&inner)
).is_ok(),
"Attempt to convert invalid data: `From<{}> for {}`",
stringify!($inner), stringify!($custom)
);
unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ TryFrom<&{SliceInner}> ];
) => {
impl<'a> $core::convert::TryFrom<&'a $slice_inner> for $custom
where
$inner: From<&'a $slice_inner>,
{
type Error = $slice_error;
fn try_from(s: &'a $slice_inner) -> $core::result::Result<Self, Self::Error> {
<$slice_spec as $crate::SliceSpec>::validate(s)?;
let inner = <$inner>::from(s);
Ok(unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
})
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ TryFrom<{Inner}> ];
) => {
impl $core::convert::TryFrom<$inner> for $custom {
type Error = $error;
fn try_from(inner: $inner) -> $core::result::Result<Self, Self::Error> {
if let Err(e) = <$slice_spec as $crate::SliceSpec>::validate(
<$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(&inner)
) {
return Err(<$spec as $crate::OwnedSliceSpec>::convert_validation_error(e, inner));
}
Ok(unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
})
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ Default ];
) => {
impl $core::default::Default for $custom
where
for<'a> &'a $slice_custom: $core::default::Default,
$inner: $core::convert::From<$inner>,
{
fn default() -> Self {
let slice = <&$slice_custom>::default();
let slice_inner = <$slice_spec as $crate::SliceSpec>::as_inner(slice);
let inner = <$inner>::from(slice_inner);
unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ Debug ];
) => {
impl $core::fmt::Debug for $custom
where
$slice_custom: $core::fmt::Debug,
{
fn fmt(&self, f: &mut $core::fmt::Formatter<'_>) -> $core::fmt::Result {
let slice = unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
};
<$slice_custom as $core::fmt::Debug>::fmt(slice, f)
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ Display ];
) => {
impl $core::fmt::Display for $custom
where
$slice_custom: $core::fmt::Display,
{
fn fmt(&self, f: &mut $core::fmt::Formatter<'_>) -> $core::fmt::Result {
let slice = unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
};
<$slice_custom as $core::fmt::Display>::fmt(slice, f)
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ Deref<Target = {SliceCustom}> ];
) => {
impl $core::ops::Deref for $custom {
type Target = $slice_custom;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ DerefMut<Target = {SliceCustom}> ];
) => {
impl $core::ops::DerefMut for $custom {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe {
$crate::impl_std_traits_for_owned_slice!(@conv:as_mut_slice, $spec, $slice_spec, self)
}
}
}
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ FromStr ];
) => {
impl $core::str::FromStr for $custom {
type Err = $slice_error;
fn from_str(s: &str) -> $core::result::Result<Self, Self::Err> {
struct EnsureTraitBound
where
$slice_spec: $crate::SliceSpec<Inner = str>, {}
<$slice_spec as $crate::SliceSpec>::validate(s)?;
let inner = <$inner>::from(s);
Ok(unsafe {
<$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
})
}
}
};
(@conv:as_slice, $spec:ty, $slice_spec:ty, $owned_ref:expr) => {
<$slice_spec as $crate::SliceSpec>::from_inner_unchecked(
<$spec as $crate::OwnedSliceSpec>::as_slice_inner($owned_ref)
)
};
(@conv:as_mut_slice, $spec:ty, $slice_spec:ty, $owned_ref:expr) => {
<$slice_spec as $crate::SliceSpec>::from_inner_unchecked_mut(
<$spec as $crate::OwnedSliceSpec>::as_slice_inner_mut($owned_ref)
)
};
(
@impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
$slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
rest=[ $($rest:tt)* ];
) => {
compile_error!(concat!("Unsupported target: ", stringify!($($rest)*)));
};
}
#[macro_export]
macro_rules! impl_cmp_for_owned_slice {
(
Spec {
spec: $spec:ty,
custom: $custom:ty,
inner: $inner:ty,
slice_custom: $slice_custom:ty,
slice_inner: $slice_inner:ty,
base: $base:ident,
};
Cmp { $($cmp_targets:ident),* };
$($rest:tt)*
) => {
$crate::impl_cmp_for_owned_slice! {
@full;
Std {
core: std,
alloc: std,
};
Spec {
spec: $spec,
custom: $custom,
inner: $inner,
slice_custom: $slice_custom,
slice_inner: $slice_inner,
base: $base,
};
Cmp { $($cmp_targets),* };
$($rest)*
}
};
(
Std {
core: $core:ident,
alloc: $alloc:ident,
};
Spec {
spec: $spec:ty,
custom: $custom:ty,
inner: $inner:ty,
slice_custom: $slice_custom:ty,
slice_inner: $slice_inner:ty,
base: $base:ident,
};
Cmp { $($cmp_targets:ident),* };
$($rest:tt)*
) => {
$crate::impl_cmp_for_owned_slice! {
@full;
Std {
core: $core,
alloc: $alloc,
};
Spec {
spec: $spec,
custom: $custom,
inner: $inner,
slice_custom: $slice_custom,
slice_inner: $slice_inner,
base: $base,
};
Cmp { $($cmp_targets),* };
$($rest)*
}
};
(
@full;
Std {
core: $core:ident,
alloc: $alloc:ident,
};
Spec {
spec: $spec:ty,
custom: $custom:ty,
inner: $inner:ty,
slice_custom: $slice_custom:ty,
slice_inner: $slice_inner:ty,
base: $base:ident,
};
Cmp { PartialEq, PartialOrd };
$({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
) => {
$(
$crate::impl_cmp_for_owned_slice! {
@impl[PartialEq]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
{ ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
}
$crate::impl_cmp_for_owned_slice! {
@impl[PartialOrd]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
{ ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
}
)*
};
(
@full;
Std {
core: $core:ident,
alloc: $alloc:ident,
};
Spec {
spec: $spec:ty,
custom: $custom:ty,
inner: $inner:ty,
slice_custom: $slice_custom:ty,
slice_inner: $slice_inner:ty,
base: $base:ident,
};
Cmp { PartialEq };
$({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
) => {
$(
$crate::impl_cmp_for_owned_slice! {
@impl[PartialEq]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
{ ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
}
)*
};
(
@full;
Std {
core: $core:ident,
alloc: $alloc:ident,
};
Spec {
spec: $spec:ty,
custom: $custom:ty,
inner: $inner:ty,
slice_custom: $slice_custom:ty,
slice_inner: $slice_inner:ty,
base: $base:ident,
};
Cmp { PartialOrd };
$({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
) => {
$(
$crate::impl_cmp_for_owned_slice! {
@impl[PartialOrd]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
{ ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
}
)*
};
(
@impl[PartialEq]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
{ ($($lhs:tt)*), ($($rhs:tt)*) };
) => {
impl $core::cmp::PartialEq<
$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
> for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
{
#[inline]
fn eq(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
-> bool
{
$crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialEq]; ($slice_custom, $slice_inner, $base))(
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
)
}
}
};
(
@impl[PartialEq]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
{ ($($lhs:tt)*), ($($rhs:tt)*), rev };
) => {
impl $core::cmp::PartialEq<
$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
> for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
{
#[inline]
fn eq(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
-> bool
{
$crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialEq]; ($slice_custom, $slice_inner, $base))(
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
)
}
}
impl $core::cmp::PartialEq<
$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
> for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
{
#[inline]
fn eq(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* }))
-> bool
{
$crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialEq]; ($slice_custom, $slice_inner, $base))(
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; self),
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; other),
)
}
}
};
(
@impl[PartialOrd]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
{ ($($lhs:tt)*), ($($rhs:tt)*) };
) => {
impl $core::cmp::PartialOrd<
$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
> for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
{
#[inline]
fn partial_cmp(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
-> $core::option::Option<$core::cmp::Ordering>
{
$crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialOrd]; ($slice_custom, $slice_inner, $base))(
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
)
}
}
};
(
@impl[PartialOrd]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
{ ($($lhs:tt)*), ($($rhs:tt)*), rev };
) => {
impl $core::cmp::PartialOrd<
$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
> for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
{
#[inline]
fn partial_cmp(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
-> $core::option::Option<$core::cmp::Ordering>
{
$crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialOrd]; ($slice_custom, $slice_inner, $base))(
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
)
}
}
impl $core::cmp::PartialOrd<
$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
> for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
{
#[inline]
fn partial_cmp(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* }))
-> $core::option::Option<$core::cmp::Ordering>
{
$crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialOrd]; ($slice_custom, $slice_inner, $base))(
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; self),
$crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; other),
)
}
}
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {Custom} }) => {
$custom
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{Custom} }) => {
&$custom
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {SliceCustom} }) => {
$slice_custom
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{SliceCustom} }) => {
&$slice_custom
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { Cow<{SliceCustom}> }) => {
$alloc::borrow::Cow<'_, $slice_custom>
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {Inner} }) => {
$inner
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{Inner} }) => {
&$inner
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {SliceInner} }) => {
$slice_inner
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{SliceInner} }) => {
&$slice_inner
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { Cow<{SliceInner}> }) => {
$alloc::borrow::Cow<'_, $slice_inner>
};
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { Cow<$ty:ty> }) => { &**$ty };
(@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { $ty:ty }) => { $ty };
(@cmp_fn[PartialEq]; ($slice_custom:ty, $slice_inner:ty, Inner)) => {
<$slice_inner as core::cmp::PartialEq<$slice_inner>>::eq
};
(@cmp_fn[PartialEq]; ($slice_custom:ty, $slice_inner:ty, Custom)) => {
<$slice_custom as core::cmp::PartialEq<$slice_custom>>::eq
};
(@cmp_fn[PartialOrd]; ($slice_custom:ty, $slice_inner:ty, Inner)) => {
<$slice_inner as core::cmp::PartialOrd<$slice_inner>>::partial_cmp
};
(@cmp_fn[PartialOrd]; ($slice_custom:ty, $slice_inner:ty, Custom)) => {
<$slice_custom as core::cmp::PartialOrd<$slice_custom>>::partial_cmp
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Custom} }; $expr:expr) => {
<$spec as $crate::OwnedSliceSpec>::as_slice_inner($expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Custom} }; $expr:expr) => {
<$spec as $crate::OwnedSliceSpec>::as_slice_inner(*$expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Custom}> }; $expr:expr) => {
<$spec as $crate::OwnedSliceSpec>::as_slice_inner(&**$expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {SliceCustom} }; $expr:expr) => {
<<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::as_inner($expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{SliceCustom} }; $expr:expr) => {
<<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::as_inner(*$expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{SliceCustom}> }; $expr:expr) => {
<<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::as_inner(&**$expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Inner} }; $expr:expr) => {
<$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner($expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Inner} }; $expr:expr) => {
<$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(*$expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Inner}> }; $expr:expr) => {
<$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(&**$expr)
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {SliceInner} }; $expr:expr) => {
$expr
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{SliceInner} }; $expr:expr) => {
*$expr
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{SliceInner}> }; $expr:expr) => {
&**$expr
};
(@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { $ty:ty }; $expr:expr) => {
$core::convert::AsRef::<$inner>::as_ref($expr)
};
(@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Custom} }; $expr:expr) => {
unsafe {
<<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::from_inner_unchecked(
<$spec as $crate::OwnedSliceSpec>::as_slice_inner($expr)
)
}
};
(@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Custom} }; $expr:expr) => {
unsafe {
<<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::from_inner_unchecked(
<$spec as $crate::OwnedSliceSpec>::as_slice_inner(*$expr)
)
}
};
(@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Custom}> }; $expr:expr) => {
unsafe {
<<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::from_inner_unchecked(
<$spec as $crate::OwnedSliceSpec>::as_slice_inner(&**$expr)
)
}
};
(@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {SliceCustom} }; $expr:expr) => {
$expr
};
(@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{SliceCustom} }; $expr:expr) => {
*$expr
};
(@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{SliceCustom}> }; $expr:expr) => {
&**$expr
};
(@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { $ty:ty }; $expr:expr) => {
$core::convert::AsRef::<$custom>::as_ref($expr)
};
($($rest:tt)*) => {
compile_error!(stringify!($($rest)*));
};
}