1#[macro_export]
55macro_rules! impl_slice_spec_methods {
56 (
57 field=$field:tt;
58 methods=[$($method:ident),* $(,)?];
59 ) => {
60 $(
61 $crate::impl_slice_spec_methods! {
62 @impl; ($field);
63 $method
64 }
65 )*
66 };
67 (@impl; ($field:tt); as_inner) => {
68 #[inline]
69 fn as_inner(s: &Self::Custom) -> &Self::Inner {
70 &s.$field
71 }
72 };
73 (@impl; ($field:tt); as_inner_mut) => {
74 #[inline]
75 fn as_inner_mut(s: &mut Self::Custom) -> &mut Self::Inner {
76 &mut s.$field
77 }
78 };
79 (@impl; ($field:tt); from_inner_unchecked) => {
80 #[inline]
81 unsafe fn from_inner_unchecked(s: &Self::Inner) -> &Self::Custom {
82 &*(s as *const Self::Inner as *const Self::Custom)
83 }
84 };
85 (@impl; ($field:tt); from_inner_unchecked_mut) => {
86 #[inline]
87 unsafe fn from_inner_unchecked_mut(s: &mut Self::Inner) -> &mut Self::Custom {
88 &mut *(s as *mut Self::Inner as *mut Self::Custom)
89 }
90 };
91}
92
93#[macro_export]
228macro_rules! impl_std_traits_for_slice {
229 (
230 Spec {
231 spec: $spec:ty,
232 custom: $custom:ty,
233 inner: $inner:ty,
234 error: $error:ty,
235 };
236 $({$($rest:tt)*});* $(;)?
237 ) => {
238 $(
239 $crate::impl_std_traits_for_slice! {
240 @impl; ({std, std}, $spec, $custom, $inner, $error);
241 rest=[$($rest)*];
242 }
243 )*
244 };
245
246 (
247 Std {
248 core: $core:ident,
249 alloc: $alloc:ident,
250 };
251 Spec {
252 spec: $spec:ty,
253 custom: $custom:ty,
254 inner: $inner:ty,
255 error: $error:ty,
256 };
257 $({$($rest:tt)*});* $(;)?
258 ) => {
259 $(
260 $crate::impl_std_traits_for_slice! {
261 @impl; ({$core, $alloc}, $spec, $custom, $inner, $error);
262 rest=[$($rest)*];
263 }
264 )*
265 };
266
267 (
269 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
270 rest=[ AsMut<{Custom}> ];
271 ) => {
272 impl $core::convert::AsMut<$custom> for $custom {
273 #[inline]
274 fn as_mut(&mut self) -> &mut $custom {
275 self
276 }
277 }
278 };
279 (
280 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
281 rest=[ AsMut<$param:ty> ];
282 ) => {
283 impl $core::convert::AsMut<$param> for $custom
284 where
285 $inner: AsMut<$param>,
286 {
287 #[inline]
288 fn as_mut(&mut self) -> &mut $param {
289 <$spec as $crate::SliceSpec>::as_inner_mut(self).as_mut()
290 }
291 }
292 };
293
294 (
296 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
297 rest=[ AsRef<{Custom}> ];
298 ) => {
299 impl $core::convert::AsRef<$custom> for $custom {
300 #[inline]
301 fn as_ref(&self) -> &$custom {
302 self
303 }
304 }
305 };
306 (
307 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
308 rest=[ AsRef<{Custom}> for Cow<{Custom}> ];
309 ) => {
310 impl<'a> $core::convert::AsRef<$custom> for $alloc::borrow::Cow<'a, $custom> {
311 #[inline]
312 fn as_ref(&self) -> &$custom {
313 &**self
314 }
315 }
316 };
317 (
318 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
319 rest=[ AsRef<$param:ty> ];
320 ) => {
321 impl $core::convert::AsRef<$param> for $custom
322 where
323 $inner: AsRef<$param>,
324 {
325 #[inline]
326 fn as_ref(&self) -> &$param {
327 <$spec as $crate::SliceSpec>::as_inner(self).as_ref()
328 }
329 }
330 };
331 (
332 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
333 rest=[ AsRef<$param:ty> for Cow<{Custom}> ];
334 ) => {
335 impl<'a> $core::convert::AsRef<$param> for $alloc::borrow::Cow<'a, $custom>
336 where
337 $inner: AsRef<$param>,
338 {
339 #[inline]
340 fn as_ref(&self) -> &$param {
341 <$spec as $crate::SliceSpec>::as_inner(&**self).as_ref()
342 }
343 }
344 };
345
346 (
348 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
349 rest=[ From<&{Inner}> for &{Custom} ];
350 ) => {
351 impl<'a> $core::convert::From<&'a $inner> for &'a $custom {
352 fn from(s: &'a $inner) -> Self {
353 assert!(
354 <$spec as $crate::SliceSpec>::validate(s).is_ok(),
355 "Attempt to convert invalid data: `From<&{}> for &{}`",
356 stringify!($inner), stringify!($custom)
357 );
358 unsafe {
359 <$spec as $crate::SliceSpec>::from_inner_unchecked(s)
365 }
366 }
367 }
368 };
369 (
370 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
371 rest=[ From<&mut {Inner}> for &mut {Custom} ];
372 ) => {
373 impl<'a> $core::convert::From<&'a mut $inner> for &'a mut $custom {
374 fn from(s: &'a mut $inner) -> Self {
375 assert!(
376 <$spec as $crate::SliceSpec>::validate(s).is_ok(),
377 "Attempt to convert invalid data: `From<&mut {}> for &mut {}`",
378 stringify!($inner), stringify!($custom)
379 );
380 unsafe {
381 <$spec as $crate::SliceSpec>::from_inner_unchecked_mut(s)
387 }
388 }
389 }
390 };
391 (
392 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
393 rest=[ From<&{Custom}> for &{Inner} ];
394 ) => {
395 impl<'a> $core::convert::From<&'a $custom> for &'a $inner {
396 fn from(s: &'a $custom) -> Self {
397 <$spec as $crate::SliceSpec>::as_inner(s)
398 }
399 }
400 };
401 (
402 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
403 rest=[ From<&mut {Custom}> for &mut {Inner} ];
404 ) => {
405 impl<'a> $core::convert::From<&'a mut $custom> for &'a mut $inner {
406 fn from(s: &'a mut $custom) -> Self {
407 <$spec as $crate::SliceSpec>::as_inner_mut(s)
408 }
409 }
410 };
411
412 (
414 @impl [smartptr]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
415 rest=[ From<&{Custom}> for $($smartptr:ident)::* <{Custom}> ];
416 ) => {
417 impl<'a> $core::convert::From<&'a $custom> for $($smartptr)::* <$custom>
418 where
419 $($smartptr)::* <$inner>: $core::convert::From<&'a $inner>,
420 {
421 fn from(s: &'a $custom) -> Self {
422 let inner = <$spec as $crate::SliceSpec>::as_inner(s);
423 let buf = $($smartptr)::* ::<$inner>::from(inner);
424 unsafe {
425 $($smartptr)::* ::<$custom>::from_raw(
433 $($smartptr)::* ::<$inner>::into_raw(buf) as *mut $custom
434 )
435 }
436 }
437 }
438 };
439 (
440 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
441 rest=[ From<&{Custom}> for Arc<{Custom}> ];
442 ) => {
443 $crate::impl_std_traits_for_slice! {
444 @impl [smartptr]; ({$core, $alloc}, $spec, $custom, $inner, $error);
445 rest=[ From<&{Custom}> for $alloc::sync::Arc <{Custom}> ];
446 }
447 };
448 (
449 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
450 rest=[ From<&{Custom}> for Box<{Custom}> ];
451 ) => {
452 $crate::impl_std_traits_for_slice! {
453 @impl [smartptr]; ({$core, $alloc}, $spec, $custom, $inner, $error);
454 rest=[ From<&{Custom}> for $alloc::boxed::Box <{Custom}> ];
455 }
456 };
457 (
458 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
459 rest=[ From<&{Custom}> for Rc<{Custom}> ];
460 ) => {
461 $crate::impl_std_traits_for_slice! {
462 @impl [smartptr]; ({$core, $alloc}, $spec, $custom, $inner, $error);
463 rest=[ From<&{Custom}> for $alloc::rc::Rc <{Custom}> ];
464 }
465 };
466
467 (
469 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
470 rest=[ TryFrom<&{Inner}> for &{Custom} ];
471 ) => {
472 impl<'a> $core::convert::TryFrom<&'a $inner> for &'a $custom {
473 type Error = $error;
474
475 fn try_from(s: &'a $inner) -> $core::result::Result<Self, Self::Error> {
476 <$spec as $crate::SliceSpec>::validate(s)?;
477 Ok(unsafe {
478 <$spec as $crate::SliceSpec>::from_inner_unchecked(s)
484 })
485 }
486 }
487 };
488 (
489 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
490 rest=[ TryFrom<&mut {Inner}> for &mut {Custom} ];
491 ) => {
492 impl<'a> $core::convert::TryFrom<&'a mut $inner> for &'a mut $custom {
493 type Error = $error;
494
495 fn try_from(s: &'a mut $inner) -> $core::result::Result<Self, Self::Error> {
496 <$spec as $crate::SliceSpec>::validate(s)?;
497 Ok(unsafe {
498 <$spec as $crate::SliceSpec>::from_inner_unchecked_mut(s)
504 })
505 }
506 }
507 };
508
509 (
511 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
512 rest=[ Default for &{Custom} ];
513 ) => {
514 impl<'a> $core::default::Default for &'a $custom
515 where
516 &'a $inner: $core::default::Default,
517 {
518 fn default() -> Self {
519 let inner = <&'a $inner as $core::default::Default>::default();
520 assert!(
521 <$spec as $crate::SliceSpec>::validate(inner).is_ok(),
522 "Attempt to create invalid data: `Default for &{}`",
523 stringify!($custom)
524 );
525 unsafe {
526 <$spec as $crate::SliceSpec>::from_inner_unchecked(inner)
532 }
533 }
534 }
535 };
536 (
537 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
538 rest=[ Default for &mut {Custom} ];
539 ) => {
540 impl<'a> $core::default::Default for &'a mut $custom
541 where
542 &'a mut $inner: $core::default::Default,
543 {
544 fn default() -> Self {
545 let inner = <&'a mut $inner as $core::default::Default>::default();
546 assert!(
547 <$spec as $crate::SliceSpec>::validate(inner).is_ok(),
548 "Attempt to create invalid data: `Default for &{}`",
549 stringify!($custom)
550 );
551 unsafe {
552 <$spec as $crate::SliceSpec>::from_inner_unchecked_mut(inner)
558 }
559 }
560 }
561 };
562
563 (
565 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
566 rest=[ Debug ];
567 ) => {
568 impl $core::fmt::Debug for $custom
569 where
570 $inner: $core::fmt::Debug,
571 {
572 fn fmt(&self, f: &mut $core::fmt::Formatter<'_>) -> $core::fmt::Result {
573 let inner = <$spec as $crate::SliceSpec>::as_inner(self);
574 <$inner as $core::fmt::Debug>::fmt(inner, f)
575 }
576 }
577 };
578
579 (
581 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
582 rest=[ Display ];
583 ) => {
584 impl $core::fmt::Display for $custom
585 where
586 $inner: $core::fmt::Display,
587 {
588 fn fmt(&self, f: &mut $core::fmt::Formatter<'_>) -> $core::fmt::Result {
589 let inner = <$spec as $crate::SliceSpec>::as_inner(self);
590 <$inner as $core::fmt::Display>::fmt(inner, f)
591 }
592 }
593 };
594
595 (
597 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
598 rest=[ Deref<Target = {Inner}> ];
599 ) => {
600 impl $core::ops::Deref for $custom {
601 type Target = $inner;
602
603 #[inline]
604 fn deref(&self) -> &Self::Target {
605 <$spec as $crate::SliceSpec>::as_inner(self)
606 }
607 }
608 };
609
610 (
612 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
613 rest=[ DerefMut<Target = {Inner}> ];
614 ) => {
615 impl $core::ops::DerefMut for $custom {
616 #[inline]
617 fn deref_mut(&mut self) -> &mut Self::Target {
618 <$spec as $crate::SliceSpec>::as_inner_mut(self)
619 }
620 }
621 };
622
623 (
625 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty);
626 rest=[ $($rest:tt)* ];
627 ) => {
628 compile_error!(concat!("Unsupported target: ", stringify!($($rest)*)));
629 };
630}
631
632#[macro_export]
745macro_rules! impl_cmp_for_slice {
746 (
747 Spec {
748 spec: $spec:ty,
749 custom: $custom:ty,
750 inner: $inner:ty,
751 base: $base:ident,
752 };
753 Cmp { $($cmp_targets:ident),* };
754 $($rest:tt)*
755 ) => {
756 $crate::impl_cmp_for_slice! {
757 @full;
758 Std {
759 core: std,
760 alloc: std,
761 };
762 Spec {
763 spec: $spec,
764 custom: $custom,
765 inner: $inner,
766 base: $base,
767 };
768 Cmp { $($cmp_targets),* };
769 $($rest)*
770 }
771 };
772 (
773 Std {
774 core: $core:ident,
775 alloc: $alloc:ident,
776 };
777 Spec {
778 spec: $spec:ty,
779 custom: $custom:ty,
780 inner: $inner:ty,
781 base: $base:ident,
782 };
783 Cmp { $($cmp_targets:ident),* };
784 $($rest:tt)*
785 ) => {
786 $crate::impl_cmp_for_slice! {
787 @full;
788 Std {
789 core: $core,
790 alloc: $alloc,
791 };
792 Spec {
793 spec: $spec,
794 custom: $custom,
795 inner: $inner,
796 base: $base,
797 };
798 Cmp { $($cmp_targets),* };
799 $($rest)*
800 }
801 };
802
803 (
804 @full;
805 Std {
806 core: $core:ident,
807 alloc: $alloc:ident,
808 };
809 Spec {
810 spec: $spec:ty,
811 custom: $custom:ty,
812 inner: $inner:ty,
813 base: $base:ident,
814 };
815 Cmp { PartialEq, PartialOrd };
816 $({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
817 ) => {
818 $(
819 $crate::impl_cmp_for_slice! {
820 @impl[PartialEq]; ({$core, $alloc}, $spec, $custom, $inner, $base);
821 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
822 }
823 $crate::impl_cmp_for_slice! {
824 @impl[PartialOrd]; ({$core, $alloc}, $spec, $custom, $inner, $base);
825 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
826 }
827 )*
828 };
829 (
830 @full;
831 Std {
832 core: $core:ident,
833 alloc: $alloc:ident,
834 };
835 Spec {
836 spec: $spec:ty,
837 custom: $custom:ty,
838 inner: $inner:ty,
839 base: $base:ident,
840 };
841 Cmp { PartialEq };
842 $({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
843 ) => {
844 $(
845 $crate::impl_cmp_for_slice! {
846 @impl[PartialEq]; ({$core, $alloc}, $spec, $custom, $inner, $base);
847 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
848 }
849 )*
850 };
851 (
852 @full;
853 Std {
854 core: $core:ident,
855 alloc: $alloc:ident,
856 };
857 Spec {
858 spec: $spec:ty,
859 custom: $custom:ty,
860 inner: $inner:ty,
861 base: $base:ident,
862 };
863 Cmp { PartialOrd };
864 $({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
865 ) => {
866 $(
867 $crate::impl_cmp_for_slice! {
868 @impl[PartialOrd]; ({$core, $alloc}, $spec, $custom, $inner, $base);
869 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
870 }
871 )*
872 };
873
874 (
875 @impl[PartialEq]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $base:ident);
876 { ($($lhs:tt)*), ($($rhs:tt)*) };
877 ) => {
878 impl $core::cmp::PartialEq<
879 $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })
880 > for $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* })
881 {
882 #[inline]
883 fn eq(&self, other: &$crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })) -> bool {
884 $crate::impl_cmp_for_slice!(@cmp_fn[PartialEq]; ($custom, $inner, $base))(
885 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($lhs)* }; self),
886 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($rhs)* }; other),
887 )
888 }
889 }
890 };
891 (
892 @impl[PartialEq]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $base:ident);
893 { ($($lhs:tt)*), ($($rhs:tt)*), rev };
894 ) => {
895 impl $core::cmp::PartialEq<
896 $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })
897 > for $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* })
898 {
899 #[inline]
900 fn eq(&self, other: &$crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })) -> bool {
901 $crate::impl_cmp_for_slice!(@cmp_fn[PartialEq]; ($custom, $inner, $base))(
902 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($lhs)* }; self),
903 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($rhs)* }; other),
904 )
905 }
906 }
907 impl $core::cmp::PartialEq<
908 $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* })
909 > for $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })
910 {
911 #[inline]
912 fn eq(&self, other: &$crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* })) -> bool {
913 $crate::impl_cmp_for_slice!(@cmp_fn[PartialEq]; ($custom, $inner, $base))(
914 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($rhs)* }; self),
915 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($lhs)* }; other),
916 )
917 }
918 }
919 };
920 (
921 @impl[PartialOrd]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $base:ident);
922 { ($($lhs:tt)*), ($($rhs:tt)*) };
923 ) => {
924 impl $core::cmp::PartialOrd<
925 $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })
926 > for $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* })
927 {
928 #[inline]
929 fn partial_cmp(&self, other: &$crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* }))
930 -> $core::option::Option<$core::cmp::Ordering>
931 {
932 $crate::impl_cmp_for_slice!(@cmp_fn[PartialOrd]; ($custom, $inner, $base))(
933 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($lhs)* }; self),
934 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($rhs)* }; other),
935 )
936 }
937 }
938 };
939 (
940 @impl[PartialOrd]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $base:ident);
941 { ($($lhs:tt)*), ($($rhs:tt)*), rev };
942 ) => {
943 impl $core::cmp::PartialOrd<
944 $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })
945 > for $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* })
946 {
947 #[inline]
948 fn partial_cmp(&self, other: &$crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* }))
949 -> $core::option::Option<$core::cmp::Ordering>
950 {
951 $crate::impl_cmp_for_slice!(@cmp_fn[PartialOrd]; ($custom, $inner, $base))(
952 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($lhs)* }; self),
953 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($rhs)* }; other),
954 )
955 }
956 }
957 impl $core::cmp::PartialOrd<
958 $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* })
959 > for $crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($rhs)* })
960 {
961 #[inline]
962 fn partial_cmp(&self, other: &$crate::impl_cmp_for_slice!(@type; ({$core, $alloc}, $custom, $inner); { $($lhs)* }))
963 -> $core::option::Option<$core::cmp::Ordering>
964 {
965 $crate::impl_cmp_for_slice!(@cmp_fn[PartialOrd]; ($custom, $inner, $base))(
966 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($rhs)* }; self),
967 $crate::impl_cmp_for_slice!(@expr[$base]; ({$core, $alloc}, $spec, $custom, $inner); { $($lhs)* }; other),
968 )
969 }
970 }
971 };
972
973 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty); { {Custom} }) => { $custom };
974 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty); { &{Custom} }) => { &$custom };
975 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty); { Cow<{Custom}> }) => { $alloc::borrow::Cow<'_, $custom> };
976 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty); { {Inner} }) => { $inner };
977 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty); { &{Inner} }) => { &$inner };
978 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty); { Cow<{Inner}> }) => { $alloc::borrow::Cow<'_, $inner> };
979 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty); { $ty:ty }) => { $ty };
980
981 (@cmp_fn[PartialEq]; ($custom:ty, $inner:ty, Inner)) => { <$inner as core::cmp::PartialEq<$inner>>::eq };
982 (@cmp_fn[PartialEq]; ($custom:ty, $inner:ty, Custom)) => { <$custom as core::cmp::PartialEq<$custom>>::eq };
983 (@cmp_fn[PartialOrd]; ($custom:ty, $inner:ty, Inner)) => { <$inner as core::cmp::PartialOrd<$inner>>::partial_cmp };
984 (@cmp_fn[PartialOrd]; ($custom:ty, $inner:ty, Custom)) => { <$custom as core::cmp::PartialOrd<$custom>>::partial_cmp };
985
986 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Custom} }; $expr:expr) => {
987 <$spec as $crate::SliceSpec>::as_inner($expr)
988 };
989 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Custom} }; $expr:expr) => {
990 <$spec as $crate::SliceSpec>::as_inner(*$expr)
991 };
992 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Custom}> }; $expr:expr) => {
993 <$spec as $crate::SliceSpec>::as_inner(&**$expr)
994 };
995 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Inner} }; $expr:expr) => {
996 $expr
997 };
998 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Inner} }; $expr:expr) => {
999 *$expr
1000 };
1001 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Inner}> }; $expr:expr) => {
1002 &**$expr
1003 };
1004 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { $ty:ty }; $expr:expr) => {
1005 $core::convert::AsRef::<$inner>::as_ref($expr)
1006 };
1007 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Custom} }; $expr:expr) => {
1008 $expr
1009 };
1010 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Custom} }; $expr:expr) => {
1011 *$expr
1012 };
1013 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Custom}> }; $expr:expr) => {
1014 &**$expr
1015 };
1016 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { $ty:ty }; $expr:expr) => {
1017 $core::convert::AsRef::<$custom>::as_ref($expr)
1018 };
1019
1020 ($($rest:tt)*) => {
1021 compile_error!(stringify!($($rest)*));
1022 };
1023}