1 | // Copyright 2024 The Fuchsia Authors |
2 | // |
3 | // Licensed under the 2-Clause BSD License <LICENSE-BSD or |
4 | // https://opensource.org/license/bsd-2-clause>, Apache License, Version 2.0 |
5 | // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
6 | // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
7 | // This file may not be copied, modified, or distributed except according to |
8 | // those terms. |
9 | |
10 | //! Deprecated items. These are kept separate so that they don't clutter up |
11 | //! other modules. |
12 | |
13 | use super::*; |
14 | |
15 | impl<B, T> Ref<B, T> |
16 | where |
17 | B: ByteSlice, |
18 | T: KnownLayout + Immutable + ?Sized, |
19 | { |
20 | #[deprecated (since = "0.8.0" , note = "renamed to `Ref::from_bytes`" )] |
21 | #[doc (hidden)] |
22 | #[must_use = "has no side effects" ] |
23 | #[inline (always)] |
24 | pub fn new(bytes: B) -> Option<Ref<B, T>> { |
25 | Self::from_bytes(source:bytes).ok() |
26 | } |
27 | } |
28 | |
29 | impl<B, T> Ref<B, T> |
30 | where |
31 | B: SplitByteSlice, |
32 | T: KnownLayout + Immutable + ?Sized, |
33 | { |
34 | #[deprecated (since = "0.8.0" , note = "renamed to `Ref::from_prefix`" )] |
35 | #[doc (hidden)] |
36 | #[must_use = "has no side effects" ] |
37 | #[inline (always)] |
38 | pub fn new_from_prefix(bytes: B) -> Option<(Ref<B, T>, B)> { |
39 | Self::from_prefix(source:bytes).ok() |
40 | } |
41 | } |
42 | |
43 | impl<B, T> Ref<B, T> |
44 | where |
45 | B: SplitByteSlice, |
46 | T: KnownLayout + Immutable + ?Sized, |
47 | { |
48 | #[deprecated (since = "0.8.0" , note = "renamed to `Ref::from_suffix`" )] |
49 | #[doc (hidden)] |
50 | #[must_use = "has no side effects" ] |
51 | #[inline (always)] |
52 | pub fn new_from_suffix(bytes: B) -> Option<(B, Ref<B, T>)> { |
53 | Self::from_suffix(source:bytes).ok() |
54 | } |
55 | } |
56 | |
57 | impl<B, T> Ref<B, T> |
58 | where |
59 | B: ByteSlice, |
60 | T: Unaligned + KnownLayout + Immutable + ?Sized, |
61 | { |
62 | #[deprecated ( |
63 | since = "0.8.0" , |
64 | note = "use `Ref::from_bytes`; for `T: Unaligned`, the returned `CastError` implements `Into<SizeError>`" |
65 | )] |
66 | #[doc (hidden)] |
67 | #[must_use = "has no side effects" ] |
68 | #[inline (always)] |
69 | pub fn new_unaligned(bytes: B) -> Option<Ref<B, T>> { |
70 | Self::from_bytes(source:bytes).ok() |
71 | } |
72 | } |
73 | |
74 | impl<B, T> Ref<B, T> |
75 | where |
76 | B: SplitByteSlice, |
77 | T: Unaligned + KnownLayout + Immutable + ?Sized, |
78 | { |
79 | #[deprecated ( |
80 | since = "0.8.0" , |
81 | note = "use `Ref::from_prefix`; for `T: Unaligned`, the returned `CastError` implements `Into<SizeError>`" |
82 | )] |
83 | #[doc (hidden)] |
84 | #[must_use = "has no side effects" ] |
85 | #[inline (always)] |
86 | pub fn new_unaligned_from_prefix(bytes: B) -> Option<(Ref<B, T>, B)> { |
87 | Self::from_prefix(source:bytes).ok() |
88 | } |
89 | } |
90 | |
91 | impl<B, T> Ref<B, T> |
92 | where |
93 | B: SplitByteSlice, |
94 | T: Unaligned + KnownLayout + Immutable + ?Sized, |
95 | { |
96 | #[deprecated ( |
97 | since = "0.8.0" , |
98 | note = "use `Ref::from_suffix`; for `T: Unaligned`, the returned `CastError` implements `Into<SizeError>`" |
99 | )] |
100 | #[doc (hidden)] |
101 | #[must_use = "has no side effects" ] |
102 | #[inline (always)] |
103 | pub fn new_unaligned_from_suffix(bytes: B) -> Option<(B, Ref<B, T>)> { |
104 | Self::from_suffix(source:bytes).ok() |
105 | } |
106 | } |
107 | |
108 | impl<B, T> Ref<B, [T]> |
109 | where |
110 | B: ByteSlice, |
111 | T: Immutable, |
112 | { |
113 | #[deprecated (since = "0.8.0" , note = "`Ref::from_bytes` now supports slices" )] |
114 | #[doc (hidden)] |
115 | #[inline (always)] |
116 | pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> { |
117 | Self::from_bytes(source:bytes).ok() |
118 | } |
119 | } |
120 | |
121 | impl<B, T> Ref<B, [T]> |
122 | where |
123 | B: ByteSlice, |
124 | T: Unaligned + Immutable, |
125 | { |
126 | #[deprecated ( |
127 | since = "0.8.0" , |
128 | note = "`Ref::from_bytes` now supports slices; for `T: Unaligned`, the returned `CastError` implements `Into<SizeError>`" |
129 | )] |
130 | #[doc (hidden)] |
131 | #[inline (always)] |
132 | pub fn new_slice_unaligned(bytes: B) -> Option<Ref<B, [T]>> { |
133 | Ref::from_bytes(source:bytes).ok() |
134 | } |
135 | } |
136 | |
137 | impl<'a, B, T> Ref<B, [T]> |
138 | where |
139 | B: 'a + IntoByteSlice<'a>, |
140 | T: FromBytes + Immutable, |
141 | { |
142 | #[deprecated (since = "0.8.0" , note = "`Ref::into_ref` now supports slices" )] |
143 | #[doc (hidden)] |
144 | #[inline (always)] |
145 | pub fn into_slice(self) -> &'a [T] { |
146 | Ref::into_ref(self) |
147 | } |
148 | } |
149 | |
150 | impl<'a, B, T> Ref<B, [T]> |
151 | where |
152 | B: 'a + IntoByteSliceMut<'a>, |
153 | T: FromBytes + IntoBytes + Immutable, |
154 | { |
155 | #[deprecated (since = "0.8.0" , note = "`Ref::into_mut` now supports slices" )] |
156 | #[doc (hidden)] |
157 | #[inline (always)] |
158 | pub fn into_mut_slice(self) -> &'a mut [T] { |
159 | Ref::into_mut(self) |
160 | } |
161 | } |
162 | |
163 | impl<B, T> Ref<B, [T]> |
164 | where |
165 | B: SplitByteSlice, |
166 | T: Immutable, |
167 | { |
168 | #[deprecated (since = "0.8.0" , note = "replaced by `Ref::from_prefix_with_elems`" )] |
169 | #[must_use = "has no side effects" ] |
170 | #[doc (hidden)] |
171 | #[inline (always)] |
172 | pub fn new_slice_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> { |
173 | Ref::from_prefix_with_elems(source:bytes, count).ok() |
174 | } |
175 | |
176 | #[deprecated (since = "0.8.0" , note = "replaced by `Ref::from_suffix_with_elems`" )] |
177 | #[must_use = "has no side effects" ] |
178 | #[doc (hidden)] |
179 | #[inline (always)] |
180 | pub fn new_slice_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> { |
181 | Ref::from_suffix_with_elems(source:bytes, count).ok() |
182 | } |
183 | } |
184 | |
185 | impl<B, T> Ref<B, [T]> |
186 | where |
187 | B: SplitByteSlice, |
188 | T: Unaligned + Immutable, |
189 | { |
190 | #[deprecated ( |
191 | since = "0.8.0" , |
192 | note = "use `Ref::from_prefix_with_elems`; for `T: Unaligned`, the returned `CastError` implements `Into<SizeError>`" |
193 | )] |
194 | #[doc (hidden)] |
195 | #[must_use = "has no side effects" ] |
196 | #[inline (always)] |
197 | pub fn new_slice_unaligned_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> { |
198 | Ref::from_prefix_with_elems(source:bytes, count).ok() |
199 | } |
200 | |
201 | #[deprecated ( |
202 | since = "0.8.0" , |
203 | note = "use `Ref::from_suffix_with_elems`; for `T: Unaligned`, the returned `CastError` implements `Into<SizeError>`" |
204 | )] |
205 | #[doc (hidden)] |
206 | #[must_use = "has no side effects" ] |
207 | #[inline (always)] |
208 | pub fn new_slice_unaligned_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> { |
209 | Ref::from_suffix_with_elems(source:bytes, count).ok() |
210 | } |
211 | } |
212 | |