1#![doc = include_str!("../README.md")]
2#![no_std]
3
4#[macro_export]
5macro_rules! general_wrapper {
41 ($($tt:tt)+) => {
42 $crate::wrapper! {
43 #[wrapper_impl(AsRef)]
44 #[wrapper_impl(Borrow)]
45 #[wrapper_impl(From)]
46 $($tt)+
47 }
48 };
49}
50
51#[macro_export]
52#[doc(hidden)]
53macro_rules! aligned {
54 ($($tt:tt)*) => {
55 #[cfg_attr(
73 any(
74 target_arch = "x86_64",
75 target_arch = "aarch64",
76 target_arch = "arm64ec",
77 target_arch = "powerpc64",
78 ),
79 repr(align(128))
80 )]
81 #[cfg_attr(
91 any(
92 target_arch = "arm",
93 target_arch = "mips",
94 target_arch = "mips32r6",
95 target_arch = "mips64",
96 target_arch = "mips64r6",
97 target_arch = "sparc",
98 target_arch = "hexagon",
99 ),
100 repr(align(32))
101 )]
102 #[cfg_attr(target_arch = "m68k", repr(align(16)))]
107 #[cfg_attr(target_arch = "s390x", repr(align(256)))]
113 #[cfg_attr(
123 not(any(
124 target_arch = "x86_64",
125 target_arch = "aarch64",
126 target_arch = "arm64ec",
127 target_arch = "powerpc64",
128 target_arch = "arm",
129 target_arch = "mips",
130 target_arch = "mips32r6",
131 target_arch = "mips64",
132 target_arch = "mips64r6",
133 target_arch = "sparc",
134 target_arch = "hexagon",
135 target_arch = "m68k",
136 target_arch = "s390x",
137 )),
138 repr(align(64))
139 )]
140 $($tt)*
141 }
142}
143
144#[macro_export]
145macro_rules! wrapper {
377 (
379 @INTERNAL IMPL
380 #[wrapper_impl(AsRef $(<$target:ty>)? )]
381 $($tt:tt)*
382 ) => {
383 $crate::wrapper! {
384 @INTERNAL IMPL
385 $($tt)*
386 }
387 };
388 (
389 @INTERNAL IMPL
390 #[wrapper_impl(AsMut $(<$target:ty>)? )]
391 $($tt:tt)*
392 ) => {
393 $crate::wrapper! {
394 @INTERNAL IMPL
395 $($tt)*
396 }
397 };
398 (
399 @INTERNAL IMPL
400 #[wrapper_impl(ConstAsMut $(<$target:ty>)? )]
401 $($tt:tt)*
402 ) => {
403 $crate::wrapper! {
404 @INTERNAL IMPL
405 $($tt)*
406 }
407 };
408 (
409 @INTERNAL IMPL
410 #[wrapper_impl(Borrow $(<$target:ty>)? )]
411 $($tt:tt)*
412 ) => {
413 $crate::wrapper! {
414 @INTERNAL IMPL
415 $($tt)*
416 }
417 };
418 (
419 @INTERNAL IMPL
420 #[wrapper_impl(BorrowMut $(<$target:ty>)? )]
421 $($tt:tt)*
422 ) => {
423 $crate::wrapper! {
424 @INTERNAL IMPL
425 $($tt)*
426 }
427 };
428 (
429 @INTERNAL IMPL
430 #[wrapper_impl(Deref $(<$target:ty>)? )]
431 $($tt:tt)*
432 ) => {
433 $crate::wrapper! {
434 @INTERNAL IMPL
435 $($tt)*
436 }
437 };
438 (
439 @INTERNAL IMPL
440 #[wrapper_impl(DerefMut $(<$target:ty>)? )]
441 $($tt:tt)*
442 ) => {
443 $crate::wrapper! {
444 @INTERNAL IMPL
445 $($tt)*
446 }
447 };
448 (
449 @INTERNAL IMPL
450 #[wrapper_impl(From)]
451 $($tt:tt)*
452 ) => {
453 $crate::wrapper! {
454 @INTERNAL IMPL
455 $($tt)*
456 }
457 };
458 (
459 @INTERNAL IMPL
460 #[wrapper_impl(Debug)]
461 $($tt:tt)*
462 ) => {
463 $crate::wrapper! {
464 @INTERNAL IMPL
465 $($tt)*
466 }
467 };
468 (
469 @INTERNAL IMPL
470 #[wrapper_impl(DebugName)]
471 $($tt:tt)*
472 ) => {
473 $crate::wrapper! {
474 @INTERNAL IMPL
475 $($tt)*
476 }
477 };
478 (
479 @INTERNAL IMPL
480 #[wrapper_impl(Display)]
481 $($tt:tt)*
482 ) => {
483 $crate::wrapper! {
484 @INTERNAL IMPL
485 $($tt)*
486 }
487 };
488
489 (
491 @INTERNAL IMPL
492 #[repr(align(cache))]
493 $(#[$outer:meta])*
494 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
495 ) => {
496 $crate::aligned! {
497 $(#[$outer])*
498 $vis struct $name$(<$($lt$(:$clt$(+$dlt)*)?$(=$default)?),+>)? {
499 $inner_vis inner: $inner_ty,
501 }
502 }
503
504 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
505 #[inline(always)]
506 #[doc = concat!("Creates [`", stringify!($name), "`] from the inner value.")]
507 $inner_vis const fn from_inner(inner: $inner_ty) -> Self {
508 Self {
509 inner,
510 }
511 }
512 }
513 };
514
515 (
516 @INTERNAL IMPL
517 $(#[$outer:meta])*
518 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
519 ) => {
520 $(#[$outer])*
521 $vis struct $name$(<$($lt$(:$clt$(+$dlt)*)?$(=$default)?),+>)? {
522 $inner_vis inner: $inner_ty,
524 }
525
526 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
527 #[inline(always)]
528 #[doc = concat!("Creates [`", stringify!($name), "`] from the inner value.")]
529 $inner_vis const fn from_inner(inner: $inner_ty) -> Self {
530 Self {
531 inner,
532 }
533 }
534 }
535 };
536
537 (
540 @INTERNAL IMPL
541 #[repr(align(cache))]
542 $(#[$outer:meta])*
543 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
544 $(#[$field_inner_meta:meta])*
545 $inner_vis:vis $inner:ident: $inner_ty:ty
546 $(
547 ,
548 $(#[$field_meta:meta])*
549 $field_vis:vis $field:ident: $field_ty:ty = $field_default: expr
550 )*
551 $(,)?
552 }
553 ) => {
554 $crate::aligned! {
555 $(#[$outer])*
556 $vis struct $name$(<$($lt$(:$clt$(+$dlt)*)?$(=$default)?),+>)? {
557 $(#[$field_inner_meta])*
558 $inner_vis $inner: $inner_ty,
559 $(
560 $(#[$field_meta])*
561 $field_vis $field: $field_ty
562 ),*
563 }
564 }
565
566 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
567 #[inline(always)]
568 #[doc = concat!("Creates [`", stringify!($name), "`] from the inner value.")]
569 $inner_vis const fn from_inner($inner: $inner_ty) -> Self {
570 Self {
571 $inner,
572 $(
573 $field: $field_default,
574 )*
575 }
576 }
577 }
578 };
579
580 (
581 @INTERNAL IMPL
582 $(#[$outer:meta])*
583 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
584 $(#[$field_inner_meta:meta])*
585 $inner_vis:vis $inner:ident: $inner_ty:ty
586 $(
587 ,
588 $(#[$field_meta:meta])*
589 $field_vis:vis $field:ident: $field_ty:ty = $field_default: expr
590 )*
591 $(,)?
592 }
593 ) => {
594 $(#[$outer])*
595 $vis struct $name$(<$($lt$(:$clt$(+$dlt)*)?$(=$default)?),+>)? {
596 $(#[$field_inner_meta])*
597 $inner_vis $inner: $inner_ty,
598 $(
599 $(#[$field_meta])*
600 $field_vis $field: $field_ty
601 ),*
602 }
603
604 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
605 #[inline(always)]
606 #[doc = concat!("Creates [`", stringify!($name), "`] from the inner value.")]
607 $inner_vis const fn from_inner($inner: $inner_ty) -> Self {
608 Self {
609 $inner,
610 $(
611 $field: $field_default,
612 )*
613 }
614 }
615 }
616 };
617
618 (
620 @INTERNAL IMPL
621 #[repr(align(cache))]
622 $(#[$outer:meta])*
623 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
624 $(#[$field_inner_meta:meta])*
625 $inner_vis:vis $inner:ident: $inner_ty:ty
626 $(
627 ,
628 $(#[$field_meta:meta])*
629 $field_vis:vis $field:ident: $field_ty:ty
630 )*
631 $(,)?
632 }
633 ) => {
634 $crate::aligned! {
635 $(#[$outer])*
636 $vis struct $name$(<$($lt$(:$clt$(+$dlt)*)?$(=$default)?),+>)? {
637 $(#[$field_inner_meta])*
638 $inner_vis $inner: $inner_ty
639 $(
640 ,
641 $(#[$field_meta])*
642 $field_vis $field: $field_ty
643 )*
644 }
645 }
646 };
647
648 (
649 @INTERNAL IMPL
650 $(#[$outer:meta])*
651 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
652 $(#[$field_inner_meta:meta])*
653 $inner_vis:vis $inner:ident: $inner_ty:ty
654 $(
655 ,
656 $(#[$field_meta:meta])*
657 $field_vis:vis $field:ident: $field_ty:ty
658 )*
659 $(,)?
660 }
661 ) => {
662 $(#[$outer])*
663 $vis struct $name$(<$($lt$(:$clt$(+$dlt)*)?$(=$default)?),+>)? {
664 $(#[$field_inner_meta])*
665 $inner_vis $inner: $inner_ty
666 $(
667 ,
668 $(#[$field_meta])*
669 $field_vis $field: $field_ty
670 )*
671 }
672 };
673
674 (
678 @INTERNAL WRAPPER_IMPL
679 #[wrapper_impl(AsRef $(<$target:ty>)? )]
680 $($tt:tt)*
681 ) => {
682 $crate::wrapper! {
683 @INTERNAL WRAPPER_IMPL_AS_REF $(<$target>)?
684 $($tt)*
685 }
686
687 $crate::wrapper! {
688 @INTERNAL WRAPPER_IMPL
689 $($tt)*
690 }
691 };
692
693 (
695 @INTERNAL WRAPPER_IMPL
696 #[wrapper_impl(AsMut $(<$target:ty>)? )]
697 $($tt:tt)*
698 ) => {
699 $crate::wrapper! {
700 @INTERNAL WRAPPER_IMPL_AS_MUT $(<$target>)?
701 $($tt)*
702 }
703
704 $crate::wrapper! {
705 @INTERNAL WRAPPER_IMPL
706 $($tt)*
707 }
708 };
709
710 (
712 @INTERNAL WRAPPER_IMPL
713 #[wrapper_impl(ConstAsMut $(<$target:ty>)? )]
714 $($tt:tt)*
715 ) => {
716 $crate::wrapper! {
717 @INTERNAL WRAPPER_IMPL_CONST_AS_MUT $(<$target>)?
718 $($tt)*
719 }
720
721 $crate::wrapper! {
722 @INTERNAL WRAPPER_IMPL
723 $($tt)*
724 }
725 };
726
727 (
729 @INTERNAL WRAPPER_IMPL
730 #[wrapper_impl(Borrow $(<$target:ty>)? )]
731 $($tt:tt)*
732 ) => {
733 $crate::wrapper! {
734 @INTERNAL WRAPPER_IMPL_BORROW $(<$target>)?
735 $($tt)*
736 }
737
738 $crate::wrapper! {
739 @INTERNAL WRAPPER_IMPL
740 $($tt)*
741 }
742 };
743
744 (
746 @INTERNAL WRAPPER_IMPL
747 #[wrapper_impl(BorrowMut $(<$target:ty>)? )]
748 $($tt:tt)*
749 ) => {
750 $crate::wrapper! {
751 @INTERNAL WRAPPER_IMPL_BORROW $(<$target>)?
752 $($tt)*
753 }
754
755 $crate::wrapper! {
756 @INTERNAL WRAPPER_IMPL_BORROW_MUT $(<$target>)?
757 $($tt)*
758 }
759
760 $crate::wrapper! {
761 @INTERNAL WRAPPER_IMPL
762 $($tt)*
763 }
764 };
765
766 (
768 @INTERNAL WRAPPER_IMPL
769 #[wrapper_impl(Debug)]
770 $($tt:tt)*
771 ) => {
772 $crate::wrapper! {
773 @INTERNAL WRAPPER_IMPL_DEBUG
774 $($tt)*
775 }
776
777 $crate::wrapper! {
778 @INTERNAL WRAPPER_IMPL
779 $($tt)*
780 }
781 };
782
783 (
785 @INTERNAL WRAPPER_IMPL
786 #[wrapper_impl(DebugName)]
787 $($tt:tt)*
788 ) => {
789 $crate::wrapper! {
790 @INTERNAL WRAPPER_IMPL_DEBUG_NAME
791 $($tt)*
792 }
793
794 $crate::wrapper! {
795 @INTERNAL WRAPPER_IMPL
796 $($tt)*
797 }
798 };
799
800 (
802 @INTERNAL WRAPPER_IMPL
803 #[wrapper_impl(Display)]
804 $($tt:tt)*
805 ) => {
806 $crate::wrapper! {
807 @INTERNAL WRAPPER_IMPL_DISPLAY
808 $($tt)*
809 }
810
811 $crate::wrapper! {
812 @INTERNAL WRAPPER_IMPL
813 $($tt)*
814 }
815 };
816
817 (
819 @INTERNAL WRAPPER_IMPL
820 #[wrapper_impl(Deref $(<$target:ty>)? )]
821 $($tt:tt)*
822 ) => {
823 $crate::wrapper! {
824 @INTERNAL WRAPPER_IMPL_DEREF $(<$target>)?
825 $($tt)*
826 }
827
828 $crate::wrapper! {
829 @INTERNAL WRAPPER_IMPL
830 $($tt)*
831 }
832 };
833
834 (
836 @INTERNAL WRAPPER_IMPL
837 #[wrapper_impl(DerefMut $(<$target:ty>)? )]
838 $($tt:tt)*
839 ) => {
840 $crate::wrapper! {
841 @INTERNAL WRAPPER_IMPL_DEREF $(<$target>)?
842 $($tt)*
843 }
844
845 $crate::wrapper! {
846 @INTERNAL WRAPPER_IMPL_DEREF_MUT $(<$target>)?
847 $($tt)*
848 }
849
850 $crate::wrapper! {
851 @INTERNAL WRAPPER_IMPL
852 $($tt)*
853 }
854 };
855
856 (
858 @INTERNAL WRAPPER_IMPL
859 #[wrapper_impl(From)]
860 $($tt:tt)*
861 ) => {
862 $crate::wrapper! {
863 @INTERNAL WRAPPER_IMPL_FROM
864 $($tt)*
865 }
866
867 $crate::wrapper! {
868 @INTERNAL WRAPPER_IMPL
869 $($tt)*
870 }
871 };
872
873 (
875 @INTERNAL WRAPPER_IMPL_AS_REF <$target:ty>
876 $(#[$meta:meta])*
877 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
878 ) => {
879 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$target> for $name$(<$($lt),+>)? {
880 fn as_ref(&self) -> &$target {
881 &self.inner
882 }
883 }
884 };
885 (
886 @INTERNAL WRAPPER_IMPL_AS_REF <$target:ty>
887 $(#[$meta:meta])*
888 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
889 $(#[$field_inner_meta:meta])*
890 $inner_vis:vis $inner:ident: $inner_ty:ty
891 $(
892 ,
893 $(#[$field_meta:meta])*
894 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
895 )*
896 $(,)?
897 }
898 ) => {
899 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$target> for $name$(<$($lt),+>)? {
900 fn as_ref(&self) -> &$target {
901 &self.$inner
902 }
903 }
904 };
905 (
906 @INTERNAL WRAPPER_IMPL_AS_REF
907 $(#[$meta:meta])*
908 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
909 ) => {
910 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$inner_ty> for $name$(<$($lt),+>)? {
911 fn as_ref(&self) -> &$inner_ty {
912 &self.inner
913 }
914 }
915
916 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
917 #[inline(always)]
919 pub const fn as_inner(&self) -> &$inner_ty {
920 &self.inner
921 }
922 }
923 };
924 (
925 @INTERNAL WRAPPER_IMPL_AS_REF
926 $(#[$meta:meta])*
927 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
928 $(#[$field_inner_meta:meta])*
929 $inner_vis:vis $inner:ident: $inner_ty:ty
930 $(
931 ,
932 $(#[$field_meta:meta])*
933 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
934 )*
935 $(,)?
936 }
937 ) => {
938 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsRef<$inner_ty> for $name$(<$($lt),+>)? {
939 fn as_ref(&self) -> &$inner_ty {
940 &self.$inner
941 }
942 }
943
944 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
945 #[inline(always)]
947 pub const fn as_inner(&self) -> &$inner_ty {
948 &self.$inner
949 }
950 }
951 };
952 (
957 @INTERNAL WRAPPER_IMPL_AS_MUT <$target:ty>
958 $(#[$meta:meta])*
959 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
960 ) => {
961 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
962 #[inline(always)]
963 fn as_mut(&mut self) -> &mut $target {
964 &mut self.inner
965 }
966 }
967 };
968 (
969 @INTERNAL WRAPPER_IMPL_AS_MUT <$target:ty>
970 $(#[$meta:meta])*
971 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
972 $(#[$field_inner_meta:meta])*
973 $inner_vis:vis $inner:ident: $inner_ty:ty
974 $(
975 ,
976 $(#[$field_meta:meta])*
977 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
978 )*
979 $(,)?
980 }
981 ) => {
982 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
983 #[inline(always)]
984 fn as_mut(&mut self) -> &mut $target {
985 &mut self.$inner
986 }
987 }
988 };
989 (
990 @INTERNAL WRAPPER_IMPL_AS_MUT
991 $(#[$meta:meta])*
992 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
993 ) => {
994 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
995 #[inline(always)]
996 fn as_mut(&mut self) -> &mut $inner_ty {
997 &mut self.inner
998 }
999 }
1000
1001 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1002 #[inline(always)]
1003 pub fn as_inner_mut(&mut self) -> &mut $inner_ty {
1005 &mut self.inner
1006 }
1007 }
1008 };
1009 (
1010 @INTERNAL WRAPPER_IMPL_AS_MUT
1011 $(#[$meta:meta])*
1012 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1013 $(#[$field_inner_meta:meta])*
1014 $inner_vis:vis $inner:ident: $inner_ty:ty
1015 $(
1016 ,
1017 $(#[$field_meta:meta])*
1018 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1019 )*
1020 $(,)?
1021 }
1022 ) => {
1023 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
1024 #[inline(always)]
1025 fn as_mut(&mut self) -> &mut $inner_ty {
1026 &mut self.$inner
1027 }
1028 }
1029
1030 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1031 #[inline(always)]
1032 pub fn as_inner_mut(&mut self) -> &mut $inner_ty {
1034 &mut self.$inner
1035 }
1036 }
1037 };
1038 (
1039 @INTERNAL WRAPPER_IMPL_CONST_AS_MUT <$target:ty>
1040 $(#[$meta:meta])*
1041 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1042 ) => {
1043 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
1044 #[inline(always)]
1045 fn as_mut(&mut self) -> &mut $target {
1046 &mut self.inner
1047 }
1048 }
1049 };
1050 (
1051 @INTERNAL WRAPPER_IMPL_CONST_AS_MUT
1052 $(#[$meta:meta])*
1053 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1054 $(#[$field_inner_meta:meta])*
1055 $inner_vis:vis $inner:ident: $inner_ty:ty
1056 $(
1057 ,
1058 $(#[$field_meta:meta])*
1059 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1060 )*
1061 $(,)?
1062 }
1063 ) => {
1064 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$target> for $name$(<$($lt),+>)? {
1065 #[inline(always)]
1066 fn as_mut(&mut self) -> &mut $target {
1067 &mut self.$inner
1068 }
1069 }
1070 };
1071 (
1072 @INTERNAL WRAPPER_IMPL_CONST_AS_MUT
1073 $(#[$meta:meta])*
1074 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1075 ) => {
1076 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
1077 #[inline(always)]
1078 fn as_mut(&mut self) -> &mut $inner_ty {
1079 &mut self.inner
1080 }
1081 }
1082
1083 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1084 #[inline(always)]
1085 pub const fn as_inner_mut(&mut self) -> &mut $inner_ty {
1087 &mut self.inner
1088 }
1089 }
1090 };
1091 (
1092 @INTERNAL WRAPPER_IMPL_CONST_AS_MUT
1093 $(#[$meta:meta])*
1094 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1095 $(#[$field_inner_meta:meta])*
1096 $inner_vis:vis $inner:ident: $inner_ty:ty
1097 $(
1098 ,
1099 $(#[$field_meta:meta])*
1100 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1101 )*
1102 $(,)?
1103 }
1104 ) => {
1105 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::AsMut<$inner_ty> for $name$(<$($lt),+>)? {
1106 #[inline(always)]
1107 fn as_mut(&mut self) -> &mut $inner_ty {
1108 &mut self.$inner
1109 }
1110 }
1111
1112 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1113 #[inline(always)]
1114 pub const fn as_inner_mut(&mut self) -> &mut $inner_ty {
1116 &mut self.$inner
1117 }
1118 }
1119 };
1120 (
1124 @INTERNAL WRAPPER_IMPL_BORROW <$target:ty>
1125 $(#[$meta:meta])*
1126 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1127 ) => {
1128 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$target> for $name$(<$($lt),+>)? {
1129 fn borrow(&self) -> &$target {
1130 &self.inner
1131 }
1132 }
1133 };
1134 (
1135 @INTERNAL WRAPPER_IMPL_BORROW <$target:ty>
1136 $(#[$meta:meta])*
1137 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1138 $(#[$field_inner_meta:meta])*
1139 $inner_vis:vis $inner:ident: $inner_ty:ty
1140 $(
1141 ,
1142 $(#[$field_meta:meta])*
1143 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1144 )*
1145 $(,)?
1146 }
1147 ) => {
1148 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$target> for $name$(<$($lt),+>)? {
1149 fn borrow(&self) -> &$target {
1150 &self.$inner
1151 }
1152 }
1153 };
1154 (
1155 @INTERNAL WRAPPER_IMPL_BORROW
1156 $(#[$meta:meta])*
1157 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1158 ) => {
1159 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$inner_ty> for $name$(<$($lt),+>)? {
1160 fn borrow(&self) -> &$inner_ty {
1161 &self.inner
1162 }
1163 }
1164 };
1165 (
1166 @INTERNAL WRAPPER_IMPL_BORROW
1167 $(#[$meta:meta])*
1168 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1169 $(#[$field_inner_meta:meta])*
1170 $inner_vis:vis $inner:ident: $inner_ty:ty
1171 $(
1172 ,
1173 $(#[$field_meta:meta])*
1174 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1175 )*
1176 $(,)?
1177 }
1178 ) => {
1179 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::Borrow<$inner_ty> for $name$(<$($lt),+>)? {
1180 fn borrow(&self) -> &$inner_ty {
1181 &self.$inner
1182 }
1183 }
1184 };
1185 (
1189 @INTERNAL WRAPPER_IMPL_BORROW_MUT <$target:ty>
1190 $(#[$meta:meta])*
1191 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1192 ) => {
1193 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$target> for $name$(<$($lt),+>)? {
1194 fn borrow_mut(&mut self) -> &mut $target {
1195 &mut self.inner
1196 }
1197 }
1198 };
1199 (
1200 @INTERNAL WRAPPER_IMPL_BORROW_MUT <$target:ty>
1201 $(#[$meta:meta])*
1202 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1203 $(#[$field_inner_meta:meta])*
1204 $inner_vis:vis $inner:ident: $inner_ty:ty
1205 $(
1206 ,
1207 $(#[$field_meta:meta])*
1208 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1209 )*
1210 $(,)?
1211 }
1212 ) => {
1213 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$target> for $name$(<$($lt),+>)? {
1214 fn borrow_mut(&mut self) -> &mut $target {
1215 &mut self.$inner
1216 }
1217 }
1218 };
1219 (
1220 @INTERNAL WRAPPER_IMPL_BORROW_MUT
1221 $(#[$meta:meta])*
1222 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1223 ) => {
1224 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$inner_ty> for $name$(<$($lt),+>)? {
1225 fn borrow_mut(&mut self) -> &mut $inner_ty {
1226 &mut self.inner
1227 }
1228 }
1229 };
1230 (
1231 @INTERNAL WRAPPER_IMPL_BORROW_MUT
1232 $(#[$meta:meta])*
1233 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1234 $(#[$field_inner_meta:meta])*
1235 $inner_vis:vis $inner:ident: $inner_ty:ty
1236 $(
1237 ,
1238 $(#[$field_meta:meta])*
1239 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1240 )*
1241 $(,)?
1242 }
1243 ) => {
1244 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::borrow::BorrowMut<$inner_ty> for $name$(<$($lt),+>)? {
1245 fn borrow_mut(&mut self) -> &mut $inner_ty {
1246 &mut self.$inner
1247 }
1248 }
1249 };
1250 (
1254 @INTERNAL WRAPPER_IMPL_DEBUG
1255 $(#[$meta:meta])*
1256 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1257 ) => {
1258 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)?
1259 where
1260 $inner_ty: ::core::fmt::Debug,
1261 {
1262 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1263 ::core::fmt::Debug::fmt(&self.inner, f)
1264 }
1265 }
1266 };
1267 (
1268 @INTERNAL WRAPPER_IMPL_DEBUG
1269 $(#[$meta:meta])*
1270 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1271 $(#[$field_inner_meta:meta])*
1272 $inner_vis:vis $inner:ident: $inner_ty:ty
1273 $(
1274 ,
1275 $(#[$field_meta:meta])*
1276 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1277 )*
1278 $(,)?
1279 }
1280 ) => {
1281 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)?
1282 where
1283 $inner_ty: ::core::fmt::Debug,
1284 {
1285 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1286 ::core::fmt::Debug::fmt(&self.$inner, f)
1287 }
1288 }
1289 };
1290 (
1294 @INTERNAL WRAPPER_IMPL_DEBUG_NAME
1295 $(#[$meta:meta])*
1296 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1297 ) => {
1298 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)? {
1299 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1300 f.debug_struct(stringify!($name)).finish()
1301 }
1302 }
1303 };
1304 (
1305 @INTERNAL WRAPPER_IMPL_DEBUG_NAME
1306 $(#[$meta:meta])*
1307 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1308 $(#[$field_inner_meta:meta])*
1309 $inner_vis:vis $inner:ident: $inner_ty:ty
1310 $(
1311 ,
1312 $(#[$field_meta:meta])*
1313 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1314 )*
1315 $(,)?
1316 }
1317 ) => {
1318 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Debug for $name$(<$($lt),+>)? {
1319 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1320 f.debug_struct(stringify!($name)).finish()
1321 }
1322 }
1323 };
1324 (
1328 @INTERNAL WRAPPER_IMPL_DISPLAY
1329 $(#[$meta:meta])*
1330 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1331 ) => {
1332 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Display for $name$(<$($lt),+>)?
1333 where
1334 $inner_ty: ::core::fmt::Display,
1335 {
1336 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1337 ::core::fmt::Display::fmt(&self.inner, f)
1338 }
1339 }
1340 };
1341 (
1342 @INTERNAL WRAPPER_IMPL_DISPLAY
1343 $(#[$meta:meta])*
1344 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1345 $(#[$field_inner_meta:meta])*
1346 $inner_vis:vis $inner:ident: $inner_ty:ty
1347 $(
1348 ,
1349 $(#[$field_meta:meta])*
1350 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1351 )*
1352 $(,)?
1353 }
1354 ) => {
1355 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::fmt::Display for $name$(<$($lt),+>)?
1356 where
1357 $inner_ty: ::core::fmt::Display,
1358 {
1359 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
1360 ::core::fmt::Display::fmt(&self.$inner, f)
1361 }
1362 }
1363 };
1364 (
1368 @INTERNAL WRAPPER_IMPL_DEREF <$target:ty>
1369 $(#[$meta:meta])*
1370 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1371 ) => {
1372 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1373 type Target = $target;
1374
1375 fn deref(&self) -> &Self::Target {
1376 &self.inner
1377 }
1378 }
1379 };
1380 (
1381 @INTERNAL WRAPPER_IMPL_DEREF <$target:ty>
1382 $(#[$meta:meta])*
1383 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1384 $(#[$field_inner_meta:meta])*
1385 $inner_vis:vis $inner:ident: $inner_ty:ty
1386 $(
1387 ,
1388 $(#[$field_meta:meta])*
1389 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1390 )*
1391 $(,)?
1392 }
1393 ) => {
1394 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1395 type Target = $target;
1396
1397 fn deref(&self) -> &Self::Target {
1398 &self.$inner
1399 }
1400 }
1401 };
1402 (
1403 @INTERNAL WRAPPER_IMPL_DEREF
1404 $(#[$meta:meta])*
1405 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1406 ) => {
1407 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1408 type Target = $inner_ty;
1409
1410 fn deref(&self) -> &Self::Target {
1411 &self.inner
1412 }
1413 }
1414 };
1415 (
1416 @INTERNAL WRAPPER_IMPL_DEREF
1417 $(#[$meta:meta])*
1418 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1419 $(#[$field_inner_meta:meta])*
1420 $inner_vis:vis $inner:ident: $inner_ty:ty
1421 $(
1422 ,
1423 $(#[$field_meta:meta])*
1424 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1425 )*
1426 $(,)?
1427 }
1428 ) => {
1429 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::Deref for $name$(<$($lt),+>)? {
1430 type Target = $inner_ty;
1431
1432 fn deref(&self) -> &Self::Target {
1433 &self.$inner
1434 }
1435 }
1436 };
1437 (
1441 @INTERNAL WRAPPER_IMPL_DEREF_MUT <$target:ty>
1442 $(#[$meta:meta])*
1443 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1444 ) => {
1445 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1446 fn deref_mut(&mut self) -> &mut Self::Target {
1447 &mut self.inner
1448 }
1449 }
1450 };
1451 (
1452 @INTERNAL WRAPPER_IMPL_DEREF_MUT <$target:ty>
1453 $(#[$meta:meta])*
1454 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1455 $(#[$field_inner_meta:meta])*
1456 $inner_vis:vis $inner:ident: $inner_ty:ty
1457 $(
1458 ,
1459 $(#[$field_meta:meta])*
1460 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1461 )*
1462 $(,)?
1463 }
1464 ) => {
1465 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1466 fn deref_mut(&mut self) -> &mut Self::Target {
1467 &mut self.$inner
1468 }
1469 }
1470 };
1471 (
1472 @INTERNAL WRAPPER_IMPL_DEREF_MUT
1473 $(#[$meta:meta])*
1474 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1475 ) => {
1476 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1477 fn deref_mut(&mut self) -> &mut Self::Target {
1478 &mut self.inner
1479 }
1480 }
1481 };
1482 (
1483 @INTERNAL WRAPPER_IMPL_DEREF_MUT
1484 $(#[$meta:meta])*
1485 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1486 $(#[$field_inner_meta:meta])*
1487 $inner_vis:vis $inner:ident: $inner_ty:ty
1488 $(
1489 ,
1490 $(#[$field_meta:meta])*
1491 $field_vis:vis $field:ident: $field_ty:ty$( = $field_default: expr)?
1492 )*
1493 $(,)?
1494 }
1495 ) => {
1496 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::ops::DerefMut for $name$(<$($lt),+>)? {
1497 fn deref_mut(&mut self) -> &mut Self::Target {
1498 &mut self.$inner
1499 }
1500 }
1501 };
1502 (
1506 @INTERNAL WRAPPER_IMPL_FROM
1507 $(#[$meta:meta])*
1508 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? ($inner_vis:vis $inner_ty:ty);
1509 ) => {
1510 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::From<$inner_ty> for $name$(<$($lt),+>)? {
1511 fn from(inner: $inner_ty) -> Self {
1512 Self::from_inner(inner)
1513 }
1514 }
1515
1516 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1517 #[allow(unreachable_pub)]
1518 #[inline(always)]
1519 #[doc = concat!("Creates [`", stringify!($name), "`] from the inner value.")]
1520 pub const fn from(inner: $inner_ty) -> Self {
1521 Self::from_inner(inner)
1522 }
1523 }
1524 };
1525 (
1526 @INTERNAL WRAPPER_IMPL_FROM
1527 $(#[$meta:meta])*
1528 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1529 $(#[$field_inner_meta:meta])*
1530 $inner_vis:vis $inner:ident: $inner_ty:ty
1531 $(
1532 ,
1533 $(#[$field_meta:meta])*
1534 $field_vis:vis $field:ident: $field_ty:ty = $field_default:expr
1535 )*
1536 $(,)?
1537 }
1538 ) => {
1539 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? ::core::convert::From<$inner_ty> for $name$(<$($lt),+>)? {
1540 fn from($inner: $inner_ty) -> Self {
1541 Self::from_inner($inner)
1542 }
1543 }
1544
1545 impl$(<$($lt$(:$clt$(+$dlt)*)?),+>)? $name$(<$($lt),+>)? {
1546 #[allow(unreachable_pub)]
1547 #[inline(always)]
1548 #[doc = concat!("Creates [`", stringify!($name), "`] from the inner value.")]
1549 pub const fn from($inner: $inner_ty) -> Self {
1550 Self::from_inner($inner)
1551 }
1552 }
1553 };
1554 (
1555 @INTERNAL WRAPPER_IMPL_FROM
1556 $(#[$meta:meta])*
1557 $vis:vis struct $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?$(=$default:tt)?),+>)? {
1558 $(#[$field_inner_meta:meta])*
1559 $inner_vis:vis $inner:ident: $inner_ty:ty
1560 $(
1561 ,
1562 $(#[$field_meta:meta])*
1563 $field_vis:vis $field:ident: $field_ty:ty
1564 )*
1565 $(,)?
1566 }
1567 ) => {
1568 compile_error!(
1569 "Invalid usage of `wrapper!` macro, cannot implement \
1570 `From` trait for wrapper types with multiple fields\
1571 but no default values given."
1572 );
1573 };
1574 (@INTERNAL WRAPPER_IMPL $($tt:tt)*) => {};
1578
1579 (@INTERNAL $($tt:tt)*) => {
1581 compile_error!(
1582 "Invalid usage of `wrapper!` macro. @INTERNAL \
1583 Please refer to the documentation for the correct syntax."
1584 );
1585 };
1586
1587 ($($tt:tt)*) => {
1589 $crate::wrapper!(@INTERNAL IMPL $($tt)*);
1590 $crate::wrapper!(@INTERNAL WRAPPER_IMPL $($tt)*);
1591 };
1592}