1#[macro_export]
12macro_rules! impl_wrapper {
13 ($type:ty; using $($using:tt)*) => {
14 $crate::impl_wrapper_inner!(__inner, ($type, T: ?Sized); $($using)*);
15 };
16 ($type:ty; ($($generics:tt)*); using $($using:tt)*) => {
17 $crate::impl_wrapper_inner!(__inner, ($type, $($generics)*); $($using)*);
18 };
19}
20
21#[doc(hidden)]
22#[macro_export]
23macro_rules! impl_wrapper_inner {
24 (__inner, ($($other:tt)*); Ref{ $($get_ref:tt)* } $($using:tt)*) => {
25 $crate::impl_wrapper_inner!(__ref, ($($other)*); { $($get_ref)* });
26 $crate::impl_wrapper_inner!(__inner, ($($other)*); $($using)*);
27 };
28 (__inner, ($($other:tt)*); Mut{ $($get_mut:tt)* } $($using:tt)*) => {
29 $crate::impl_wrapper_inner!(__mut, ($($other)*); { $($get_mut)* });
30 $crate::impl_wrapper_inner!(__inner, ($($other)*); $($using)*);
31 };
32 (__inner, ($($other:tt)*); From{ $($from:tt)* } $($using:tt)*) => {
33 $crate::impl_wrapper_inner!(__from, ($($other)*); { $($from)* });
34 $crate::impl_wrapper_inner!(__inner, ($($other)*); $($using)*);
35 };
36 (__inner, ($type:ty, $($generics:tt)*); ) => {};
37
38 (__ref, ($type:ty, $($generics:tt)*); { $($get_ref:tt)* }) => {
39 impl<$($generics)*> $crate::private::ShaderType for $type
40 where
41 T: $crate::private::ShaderType
42 {
43 type ExtraMetadata = T::ExtraMetadata;
44 const METADATA: $crate::private::Metadata<Self::ExtraMetadata> = T::METADATA.no_pod();
45
46 const UNIFORM_COMPAT_ASSERT: fn() = T::UNIFORM_COMPAT_ASSERT;
47
48 #[inline]
49 fn size(&self) -> ::core::num::NonZeroU64 {
50 <T as $crate::private::ShaderType>::size(&self$($get_ref)*)
51 }
52 }
53 impl<$($generics)*> $crate::private::ShaderSize for $type
54 where
55 T: $crate::private::ShaderSize
56 {
57 const SHADER_SIZE: ::core::num::NonZeroU64 = T::SHADER_SIZE;
58 }
59
60 impl<$($generics)*> $crate::private::RuntimeSizedArray for $type
61 where
62 T: $crate::private::RuntimeSizedArray
63 {
64 #[inline]
65 fn len(&self) -> usize {
66 <T as $crate::private::RuntimeSizedArray>::len(&self$($get_ref)*)
67 }
68 }
69
70 impl<$($generics)*> $crate::private::CalculateSizeFor for $type
71 where
72 T: $crate::private::CalculateSizeFor
73 {
74 #[inline]
75 fn calculate_size_for(nr_of_el: u64) -> ::core::num::NonZeroU64 {
76 <T as $crate::private::CalculateSizeFor>::calculate_size_for(nr_of_el)
77 }
78 }
79
80 impl<$($generics)*> $crate::private::WriteInto for $type
81 where
82 T: $crate::private::WriteInto
83 {
84 #[inline]
85 fn write_into<B: $crate::private::BufferMut>(&self, writer: &mut $crate::private::Writer<B>) {
86 <T as $crate::private::WriteInto>::write_into(&self$($get_ref)*, writer)
87 }
88 }
89 };
90 (__mut, ($type:ty, $($generics:tt)*); { $($get_mut:tt)* }) => {
91 impl<$($generics)*> $crate::private::ReadFrom for $type
92 where
93 T: $crate::private::ReadFrom
94 {
95 #[inline]
96 fn read_from<B: $crate::private::BufferRef>(&mut self, reader: &mut $crate::private::Reader<B>) {
97 <T as $crate::private::ReadFrom>::read_from(self$($get_mut)*, reader)
98 }
99 }
100 };
101 (__from, ($type:ty, $($generics:tt)*); { $($from:tt)* }) => {
102 impl<$($generics)*> $crate::private::CreateFrom for $type
103 where
104 T: $crate::private::CreateFrom
105 {
106 #[inline]
107 fn create_from<B: $crate::private::BufferRef>(reader: &mut $crate::private::Reader<B>) -> Self {
108 <$type>::$($from)*(<T as $crate::private::CreateFrom>::create_from(reader))
109 }
110 }
111 };
112}
113
114impl_wrapper!(&T; using Ref{});
115impl_wrapper!(&mut T; using Ref{} Mut{});
116impl_wrapper!(Box<T>; using Ref{} Mut{} From{ new });
117impl_wrapper!(std::borrow::Cow<'_, T>; (T: ?Sized + ToOwned<Owned = T>); using Ref{} From{ Owned });
118impl_wrapper!(std::rc::Rc<T>; using Ref{} From{ new });
119impl_wrapper!(std::sync::Arc<T>; using Ref{} From{ new });
120impl_wrapper!(core::cell::Cell<T>; (T: Copy); using Ref{ .get() } Mut{ .get_mut() } From{ new });