1#[macro_export]
175macro_rules! impl_std_traits_for_owned_slice {
176 (
177 Std {
178 core: $core:ident,
179 alloc: $alloc:ident,
180 };
181 Spec {
182 spec: $spec:ty,
183 custom: $custom:ty,
184 inner: $inner:ty,
185 error: $error:ty,
186 slice_custom: $slice_custom:ty,
187 slice_inner: $slice_inner:ty,
188 slice_error: $slice_error:ty,
189 };
190 $({$($rest:tt)*});* $(;)?
191 ) => {
192 $(
193 $crate::impl_std_traits_for_owned_slice! {
194 @impl; ({$core, $alloc}, $spec, $custom, $inner, $error,
195 <$spec as $crate::OwnedSliceSpec>::SliceSpec, $slice_custom, $slice_inner,
196 $slice_error);
197 rest=[$($rest)*];
198 }
199 )*
200 };
201
202 (
203 Spec {
204 spec: $spec:ty,
205 custom: $custom:ty,
206 inner: $inner:ty,
207 error: $error:ty,
208 slice_custom: $slice_custom:ty,
209 slice_inner: $slice_inner:ty,
210 slice_error: $slice_error:ty,
211 };
212 $({$($rest:tt)*});* $(;)?
213 ) => {
214 $(
215 $crate::impl_std_traits_for_owned_slice! {
216 @impl; ({std, std}, $spec, $custom, $inner, $error,
217 <$spec as $crate::OwnedSliceSpec>::SliceSpec, $slice_custom, $slice_inner,
218 $slice_error);
219 rest=[$($rest)*];
220 }
221 )*
222 };
223
224 (
226 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
227 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
228 rest=[ Borrow<{SliceCustom}> ];
229 ) => {
230 impl $core::borrow::Borrow<$slice_custom> for $custom {
231 #[inline]
232 fn borrow(&self) -> &$slice_custom {
233 unsafe {
234 $crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
240 }
241 }
242 }
243 };
244 (
245 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
246 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
247 rest=[ Borrow<$param:ty> ];
248 ) => {
249 impl $core::borrow::Borrow<$param> for $custom
250 where
251 $slice_inner: $core::borrow::Borrow<$param>,
252 {
253 #[inline]
254 fn borrow(&self) -> &$param {
255 <$spec as $crate::OwnedSliceSpec>::as_slice_inner(self).borrow()
256 }
257 }
258 };
259
260 (
262 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
263 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
264 rest=[ BorrowMut<{SliceCustom}> ];
265 ) => {
266 impl $core::borrow::BorrowMut<$slice_custom> for $custom {
267 #[inline]
268 fn borrow_mut(&mut self) -> &mut $slice_custom {
269 unsafe {
270 $crate::impl_std_traits_for_owned_slice!(@conv:as_mut_slice, $spec, $slice_spec, self)
276 }
277 }
278 }
279 };
280 (
281 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
282 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
283 rest=[ BorrowMut<$param:ty> ];
284 ) => {
285 impl $core::borrow::BorrowMut<$param> for $custom
286 where
287 $slice_inner: $core::borrow::BorrowMut<$param>,
288 {
289 #[inline]
290 fn borrow_mut(&mut self) -> &mut $param {
291 <$spec as $crate::OwnedSliceSpec>::as_slice_inner_mut(self).borrow_mut()
292 }
293 }
294 };
295
296 (
298 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
299 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
300 rest=[ ToOwned<Owned = {Custom}> for {SliceCustom} ];
301 ) => {
302 impl $alloc::borrow::ToOwned for $slice_custom
303 where
304 for<'a> $inner: From<&'a $slice_inner>,
305 {
306 type Owned = $custom;
307
308 fn to_owned(&self) -> Self::Owned {
309 let inner = <$inner>::from(<$slice_spec as $crate::SliceSpec>::as_inner(self));
310 unsafe {
311 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
317 }
318 }
319 }
320 };
321
322 (
324 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
325 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
326 rest=[ AsMut<{SliceCustom}> ];
327 ) => {
328 impl $core::convert::AsMut<$slice_custom> for $custom {
329 #[inline]
330 fn as_mut(&mut self) -> &mut $slice_custom {
331 unsafe {
332 $crate::impl_std_traits_for_owned_slice!(@conv:as_mut_slice, $spec, $slice_spec, self)
338 }
339 }
340 }
341 };
342 (
343 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
344 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
345 rest=[ AsMut<$param:ty> ];
346 ) => {
347 impl $core::convert::AsMut<$param> for $custom
348 where
349 $slice_inner: $core::convert::AsMut<$param>,
350 {
351 #[inline]
352 fn as_mut(&self) -> &$param {
353 <$spec as $crate::OwnedSliceSpec>::as_slice_inner_mut(self).as_mut()
354 }
355 }
356 };
357
358 (
360 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
361 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
362 rest=[ AsRef<{SliceCustom}> ];
363 ) => {
364 impl $core::convert::AsRef<$slice_custom> for $custom {
365 #[inline]
366 fn as_ref(&self) -> &$slice_custom {
367 unsafe {
368 $crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
374 }
375 }
376 }
377 };
378 (
379 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
380 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
381 rest=[ AsRef<$param:ty> ];
382 ) => {
383 impl $core::convert::AsRef<$param> for $custom
384 where
385 $slice_inner: $core::convert::AsRef<$param>,
386 {
387 #[inline]
388 fn as_ref(&self) -> &$param {
389 <$spec as $crate::OwnedSliceSpec>::as_slice_inner(self).as_ref()
390 }
391 }
392 };
393
394 (
396 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
397 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
398 rest=[ From<&{SliceInner}> ];
399 ) => {
400 impl<'a> $core::convert::From<&'a $slice_inner> for $custom
401 where
402 $inner: From<&'a $slice_inner>,
403 {
404 fn from(s: &'a $slice_inner) -> Self {
405 assert!(
406 <$slice_spec as $crate::SliceSpec>::validate(s).is_ok(),
407 "Attempt to convert invalid data: `From<&{}> for {}`",
408 stringify!($slice_inner), stringify!($custom)
409 );
410 let inner = <$inner>::from(s);
411 unsafe {
412 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
418 }
419 }
420 }
421 };
422 (
423 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
424 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
425 rest=[ From<&{SliceCustom}> ];
426 ) => {
427 impl<'a> $core::convert::From<&'a $slice_custom> for $custom
428 where
429 $inner: From<&'a $slice_inner>,
430 {
431 fn from(s: &'a $slice_custom) -> Self {
432 let inner = <$inner>::from(<$slice_spec as $crate::SliceSpec>::as_inner(s));
433 unsafe {
434 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
440 }
441 }
442 }
443 };
444 (
445 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
446 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
447 rest=[ From<{Inner}> ];
448 ) => {
449 impl $core::convert::From<$inner> for $custom {
450 fn from(inner: $inner) -> Self {
451 assert!(
452 <$slice_spec as $crate::SliceSpec>::validate(
453 <$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(&inner)
454 ).is_ok(),
455 "Attempt to convert invalid data: `From<{}> for {}`",
456 stringify!($inner), stringify!($custom)
457 );
458 unsafe {
459 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
465 }
466 }
467 }
468 };
469 (
470 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
471 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
472 rest=[ From<{Custom}> for {Inner} ];
473 ) => {
474 impl $core::convert::From<$custom> for $inner {
475 fn from(custom: $custom) -> Self {
476 <$spec as $crate::OwnedSliceSpec>::into_inner(custom)
477 }
478 }
479 };
480
481 (
483 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
484 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
485 rest=[ TryFrom<&{SliceInner}> ];
486 ) => {
487 impl<'a> $core::convert::TryFrom<&'a $slice_inner> for $custom
488 where
489 $inner: From<&'a $slice_inner>,
490 {
491 type Error = $slice_error;
492
493 fn try_from(s: &'a $slice_inner) -> $core::result::Result<Self, Self::Error> {
494 <$slice_spec as $crate::SliceSpec>::validate(s)?;
495 let inner = <$inner>::from(s);
496 Ok(unsafe {
497 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
503 })
504 }
505 }
506 };
507 (
508 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
509 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
510 rest=[ TryFrom<{Inner}> ];
511 ) => {
512 impl $core::convert::TryFrom<$inner> for $custom {
513 type Error = $error;
514
515 fn try_from(inner: $inner) -> $core::result::Result<Self, Self::Error> {
516 if let Err(e) = <$slice_spec as $crate::SliceSpec>::validate(
517 <$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(&inner)
518 ) {
519 return Err(<$spec as $crate::OwnedSliceSpec>::convert_validation_error(e, inner));
520 }
521 Ok(unsafe {
522 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
528 })
529 }
530 }
531 };
532
533 (
535 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
536 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
537 rest=[ Default ];
538 ) => {
539 impl $core::default::Default for $custom
540 where
541 for<'a> &'a $slice_custom: $core::default::Default,
542 $inner: $core::convert::From<$inner>,
543 {
544 fn default() -> Self {
545 let slice = <&$slice_custom>::default();
546 let slice_inner = <$slice_spec as $crate::SliceSpec>::as_inner(slice);
547 let inner = <$inner>::from(slice_inner);
548 unsafe {
549 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
555 }
556 }
557 }
558 };
559
560 (
562 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
563 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
564 rest=[ Debug ];
565 ) => {
566 impl $core::fmt::Debug for $custom
567 where
568 $slice_custom: $core::fmt::Debug,
569 {
570 fn fmt(&self, f: &mut $core::fmt::Formatter<'_>) -> $core::fmt::Result {
571 let slice = unsafe {
572 $crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
578 };
579 <$slice_custom as $core::fmt::Debug>::fmt(slice, f)
580 }
581 }
582 };
583
584 (
586 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
587 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
588 rest=[ Display ];
589 ) => {
590 impl $core::fmt::Display for $custom
591 where
592 $slice_custom: $core::fmt::Display,
593 {
594 fn fmt(&self, f: &mut $core::fmt::Formatter<'_>) -> $core::fmt::Result {
595 let slice = unsafe {
596 $crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
602 };
603 <$slice_custom as $core::fmt::Display>::fmt(slice, f)
604 }
605 }
606 };
607
608 (
610 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
611 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
612 rest=[ Deref<Target = {SliceCustom}> ];
613 ) => {
614 impl $core::ops::Deref for $custom {
615 type Target = $slice_custom;
616
617 #[inline]
618 fn deref(&self) -> &Self::Target {
619 unsafe {
620 $crate::impl_std_traits_for_owned_slice!(@conv:as_slice, $spec, $slice_spec, self)
626 }
627 }
628 }
629 };
630
631 (
633 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
634 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
635 rest=[ DerefMut<Target = {SliceCustom}> ];
636 ) => {
637 impl $core::ops::DerefMut for $custom {
638 #[inline]
639 fn deref_mut(&mut self) -> &mut Self::Target {
640 unsafe {
641 $crate::impl_std_traits_for_owned_slice!(@conv:as_mut_slice, $spec, $slice_spec, self)
647 }
648 }
649 }
650 };
651
652 (
654 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
655 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
656 rest=[ FromStr ];
657 ) => {
658 impl $core::str::FromStr for $custom {
659 type Err = $slice_error;
660
661 fn from_str(s: &str) -> $core::result::Result<Self, Self::Err> {
662 struct EnsureTraitBound
665 where
666 $slice_spec: $crate::SliceSpec<Inner = str>, {}
667
668 <$slice_spec as $crate::SliceSpec>::validate(s)?;
669 let inner = <$inner>::from(s);
670 Ok(unsafe {
671 <$spec as $crate::OwnedSliceSpec>::from_inner_unchecked(inner)
677 })
678 }
679 }
680 };
702
703 (@conv:as_slice, $spec:ty, $slice_spec:ty, $owned_ref:expr) => {
707 <$slice_spec as $crate::SliceSpec>::from_inner_unchecked(
708 <$spec as $crate::OwnedSliceSpec>::as_slice_inner($owned_ref)
709 )
710 };
711 (@conv:as_mut_slice, $spec:ty, $slice_spec:ty, $owned_ref:expr) => {
713 <$slice_spec as $crate::SliceSpec>::from_inner_unchecked_mut(
714 <$spec as $crate::OwnedSliceSpec>::as_slice_inner_mut($owned_ref)
715 )
716 };
717
718 (
720 @impl; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $error:ty,
721 $slice_spec:ty, $slice_custom:ty, $slice_inner:ty, $slice_error:ty);
722 rest=[ $($rest:tt)* ];
723 ) => {
724 compile_error!(concat!("Unsupported target: ", stringify!($($rest)*)));
725 };
726}
727
728#[macro_export]
847macro_rules! impl_cmp_for_owned_slice {
848 (
849 Spec {
850 spec: $spec:ty,
851 custom: $custom:ty,
852 inner: $inner:ty,
853 slice_custom: $slice_custom:ty,
854 slice_inner: $slice_inner:ty,
855 base: $base:ident,
856 };
857 Cmp { $($cmp_targets:ident),* };
858 $($rest:tt)*
859 ) => {
860 $crate::impl_cmp_for_owned_slice! {
861 @full;
862 Std {
863 core: std,
864 alloc: std,
865 };
866 Spec {
867 spec: $spec,
868 custom: $custom,
869 inner: $inner,
870 slice_custom: $slice_custom,
871 slice_inner: $slice_inner,
872 base: $base,
873 };
874 Cmp { $($cmp_targets),* };
875 $($rest)*
876 }
877 };
878 (
879 Std {
880 core: $core:ident,
881 alloc: $alloc:ident,
882 };
883 Spec {
884 spec: $spec:ty,
885 custom: $custom:ty,
886 inner: $inner:ty,
887 slice_custom: $slice_custom:ty,
888 slice_inner: $slice_inner:ty,
889 base: $base:ident,
890 };
891 Cmp { $($cmp_targets:ident),* };
892 $($rest:tt)*
893 ) => {
894 $crate::impl_cmp_for_owned_slice! {
895 @full;
896 Std {
897 core: $core,
898 alloc: $alloc,
899 };
900 Spec {
901 spec: $spec,
902 custom: $custom,
903 inner: $inner,
904 slice_custom: $slice_custom,
905 slice_inner: $slice_inner,
906 base: $base,
907 };
908 Cmp { $($cmp_targets),* };
909 $($rest)*
910 }
911 };
912
913 (
914 @full;
915 Std {
916 core: $core:ident,
917 alloc: $alloc:ident,
918 };
919 Spec {
920 spec: $spec:ty,
921 custom: $custom:ty,
922 inner: $inner:ty,
923 slice_custom: $slice_custom:ty,
924 slice_inner: $slice_inner:ty,
925 base: $base:ident,
926 };
927 Cmp { PartialEq, PartialOrd };
928 $({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
929 ) => {
930 $(
931 $crate::impl_cmp_for_owned_slice! {
932 @impl[PartialEq]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
933 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
934 }
935 $crate::impl_cmp_for_owned_slice! {
936 @impl[PartialOrd]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
937 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
938 }
939 )*
940 };
941 (
942 @full;
943 Std {
944 core: $core:ident,
945 alloc: $alloc:ident,
946 };
947 Spec {
948 spec: $spec:ty,
949 custom: $custom:ty,
950 inner: $inner:ty,
951 slice_custom: $slice_custom:ty,
952 slice_inner: $slice_inner:ty,
953 base: $base:ident,
954 };
955 Cmp { PartialEq };
956 $({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
957 ) => {
958 $(
959 $crate::impl_cmp_for_owned_slice! {
960 @impl[PartialEq]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
961 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
962 }
963 )*
964 };
965 (
966 @full;
967 Std {
968 core: $core:ident,
969 alloc: $alloc:ident,
970 };
971 Spec {
972 spec: $spec:ty,
973 custom: $custom:ty,
974 inner: $inner:ty,
975 slice_custom: $slice_custom:ty,
976 slice_inner: $slice_inner:ty,
977 base: $base:ident,
978 };
979 Cmp { PartialOrd };
980 $({ ($($lhs:tt)*), ($($rhs:tt)*) $(, $($opt:ident),*)? });* $(;)?
981 ) => {
982 $(
983 $crate::impl_cmp_for_owned_slice! {
984 @impl[PartialOrd]; ({$core, $alloc}, $spec, $custom, $inner, $slice_custom, $slice_inner, $base);
985 { ($($lhs)*), ($($rhs)*) $(, $($opt),*)? };
986 }
987 )*
988 };
989
990 (
991 @impl[PartialEq]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
992 { ($($lhs:tt)*), ($($rhs:tt)*) };
993 ) => {
994 impl $core::cmp::PartialEq<
995 $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
996 > for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
997 {
998 #[inline]
999 fn eq(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
1000 -> bool
1001 {
1002 $crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialEq]; ($slice_custom, $slice_inner, $base))(
1003 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
1004 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
1005 )
1006 }
1007 }
1008 };
1009 (
1010 @impl[PartialEq]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
1011 { ($($lhs:tt)*), ($($rhs:tt)*), rev };
1012 ) => {
1013 impl $core::cmp::PartialEq<
1014 $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
1015 > for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
1016 {
1017 #[inline]
1018 fn eq(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
1019 -> bool
1020 {
1021 $crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialEq]; ($slice_custom, $slice_inner, $base))(
1022 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
1023 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
1024 )
1025 }
1026 }
1027 impl $core::cmp::PartialEq<
1028 $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
1029 > for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
1030 {
1031 #[inline]
1032 fn eq(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* }))
1033 -> bool
1034 {
1035 $crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialEq]; ($slice_custom, $slice_inner, $base))(
1036 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; self),
1037 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; other),
1038 )
1039 }
1040 }
1041 };
1042 (
1043 @impl[PartialOrd]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
1044 { ($($lhs:tt)*), ($($rhs:tt)*) };
1045 ) => {
1046 impl $core::cmp::PartialOrd<
1047 $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
1048 > for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
1049 {
1050 #[inline]
1051 fn partial_cmp(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
1052 -> $core::option::Option<$core::cmp::Ordering>
1053 {
1054 $crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialOrd]; ($slice_custom, $slice_inner, $base))(
1055 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
1056 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
1057 )
1058 }
1059 }
1060 };
1061 (
1062 @impl[PartialOrd]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty, $base:ident);
1063 { ($($lhs:tt)*), ($($rhs:tt)*), rev };
1064 ) => {
1065 impl $core::cmp::PartialOrd<
1066 $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
1067 > for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
1068 {
1069 #[inline]
1070 fn partial_cmp(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* }))
1071 -> $core::option::Option<$core::cmp::Ordering>
1072 {
1073 $crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialOrd]; ($slice_custom, $slice_inner, $base))(
1074 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; self),
1075 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; other),
1076 )
1077 }
1078 }
1079 impl $core::cmp::PartialOrd<
1080 $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* })
1081 > for $crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($rhs)* })
1082 {
1083 #[inline]
1084 fn partial_cmp(&self, other: &$crate::impl_cmp_for_owned_slice!(@type; ({$core, $alloc}, $custom, $inner, $slice_custom, $slice_inner); { $($lhs)* }))
1085 -> $core::option::Option<$core::cmp::Ordering>
1086 {
1087 $crate::impl_cmp_for_owned_slice!(@cmp_fn[PartialOrd]; ($slice_custom, $slice_inner, $base))(
1088 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($rhs)* }; self),
1089 $crate::impl_cmp_for_owned_slice!(@expr[$base]; ({$core, $alloc}, $spec, $slice_custom, $slice_inner); { $($lhs)* }; other),
1090 )
1091 }
1092 }
1093 };
1094
1095 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {Custom} }) => {
1096 $custom
1097 };
1098 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{Custom} }) => {
1099 &$custom
1100 };
1101 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {SliceCustom} }) => {
1102 $slice_custom
1103 };
1104 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{SliceCustom} }) => {
1105 &$slice_custom
1106 };
1107 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { Cow<{SliceCustom}> }) => {
1108 $alloc::borrow::Cow<'_, $slice_custom>
1109 };
1110 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {Inner} }) => {
1111 $inner
1112 };
1113 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{Inner} }) => {
1114 &$inner
1115 };
1116 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { {SliceInner} }) => {
1117 $slice_inner
1118 };
1119 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { &{SliceInner} }) => {
1120 &$slice_inner
1121 };
1122 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { Cow<{SliceInner}> }) => {
1123 $alloc::borrow::Cow<'_, $slice_inner>
1124 };
1125 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { Cow<$ty:ty> }) => { &**$ty };
1126 (@type; ({$core:ident, $alloc:ident}, $custom:ty, $inner:ty, $slice_custom:ty, $slice_inner:ty); { $ty:ty }) => { $ty };
1127
1128 (@cmp_fn[PartialEq]; ($slice_custom:ty, $slice_inner:ty, Inner)) => {
1129 <$slice_inner as core::cmp::PartialEq<$slice_inner>>::eq
1130 };
1131 (@cmp_fn[PartialEq]; ($slice_custom:ty, $slice_inner:ty, Custom)) => {
1132 <$slice_custom as core::cmp::PartialEq<$slice_custom>>::eq
1133 };
1134 (@cmp_fn[PartialOrd]; ($slice_custom:ty, $slice_inner:ty, Inner)) => {
1135 <$slice_inner as core::cmp::PartialOrd<$slice_inner>>::partial_cmp
1136 };
1137 (@cmp_fn[PartialOrd]; ($slice_custom:ty, $slice_inner:ty, Custom)) => {
1138 <$slice_custom as core::cmp::PartialOrd<$slice_custom>>::partial_cmp
1139 };
1140
1141 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Custom} }; $expr:expr) => {
1142 <$spec as $crate::OwnedSliceSpec>::as_slice_inner($expr)
1143 };
1144 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Custom} }; $expr:expr) => {
1145 <$spec as $crate::OwnedSliceSpec>::as_slice_inner(*$expr)
1146 };
1147 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Custom}> }; $expr:expr) => {
1148 <$spec as $crate::OwnedSliceSpec>::as_slice_inner(&**$expr)
1149 };
1150 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {SliceCustom} }; $expr:expr) => {
1151 <<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::as_inner($expr)
1152 };
1153 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{SliceCustom} }; $expr:expr) => {
1154 <<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::as_inner(*$expr)
1155 };
1156 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{SliceCustom}> }; $expr:expr) => {
1157 <<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::as_inner(&**$expr)
1158 };
1159 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Inner} }; $expr:expr) => {
1160 <$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner($expr)
1161 };
1162 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Inner} }; $expr:expr) => {
1163 <$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(*$expr)
1164 };
1165 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Inner}> }; $expr:expr) => {
1166 <$spec as $crate::OwnedSliceSpec>::inner_as_slice_inner(&**$expr)
1167 };
1168 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {SliceInner} }; $expr:expr) => {
1169 $expr
1170 };
1171 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{SliceInner} }; $expr:expr) => {
1172 *$expr
1173 };
1174 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{SliceInner}> }; $expr:expr) => {
1175 &**$expr
1176 };
1177 (@expr[Inner]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { $ty:ty }; $expr:expr) => {
1178 $core::convert::AsRef::<$inner>::as_ref($expr)
1179 };
1180
1181 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {Custom} }; $expr:expr) => {
1182 unsafe {
1183 <<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::from_inner_unchecked(
1189 <$spec as $crate::OwnedSliceSpec>::as_slice_inner($expr)
1190 )
1191 }
1192 };
1193 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{Custom} }; $expr:expr) => {
1194 unsafe {
1195 <<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::from_inner_unchecked(
1201 <$spec as $crate::OwnedSliceSpec>::as_slice_inner(*$expr)
1202 )
1203 }
1204 };
1205 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{Custom}> }; $expr:expr) => {
1206 unsafe {
1207 <<$spec as $crate::OwnedSliceSpec>::SliceSpec as $crate::SliceSpec>::from_inner_unchecked(
1213 <$spec as $crate::OwnedSliceSpec>::as_slice_inner(&**$expr)
1214 )
1215 }
1216 };
1217 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { {SliceCustom} }; $expr:expr) => {
1218 $expr
1219 };
1220 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { &{SliceCustom} }; $expr:expr) => {
1221 *$expr
1222 };
1223 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { Cow<{SliceCustom}> }; $expr:expr) => {
1224 &**$expr
1225 };
1226 (@expr[Custom]; ({$core:ident, $alloc:ident}, $spec:ty, $custom:ty, $inner:ty); { $ty:ty }; $expr:expr) => {
1227 $core::convert::AsRef::<$custom>::as_ref($expr)
1228 };
1229
1230 ($($rest:tt)*) => {
1231 compile_error!(stringify!($($rest)*));
1232 };
1233}