/rust/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.8.14/src/deprecated.rs
Line | Count | Source (jump to first uncovered line) |
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 | 0 | pub fn new(bytes: B) -> Option<Ref<B, T>> { |
25 | 0 | Self::from_bytes(bytes).ok() |
26 | 0 | } |
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 | 0 | pub fn new_from_prefix(bytes: B) -> Option<(Ref<B, T>, B)> { |
39 | 0 | Self::from_prefix(bytes).ok() |
40 | 0 | } |
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 | 0 | pub fn new_from_suffix(bytes: B) -> Option<(B, Ref<B, T>)> { |
53 | 0 | Self::from_suffix(bytes).ok() |
54 | 0 | } |
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 | 0 | pub fn new_unaligned(bytes: B) -> Option<Ref<B, T>> { |
70 | 0 | Self::from_bytes(bytes).ok() |
71 | 0 | } |
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 | 0 | pub fn new_unaligned_from_prefix(bytes: B) -> Option<(Ref<B, T>, B)> { |
87 | 0 | Self::from_prefix(bytes).ok() |
88 | 0 | } |
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 | 0 | pub fn new_unaligned_from_suffix(bytes: B) -> Option<(B, Ref<B, T>)> { |
104 | 0 | Self::from_suffix(bytes).ok() |
105 | 0 | } |
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 | 0 | pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> { |
117 | 0 | Self::from_bytes(bytes).ok() |
118 | 0 | } |
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 | 0 | pub fn new_slice_unaligned(bytes: B) -> Option<Ref<B, [T]>> { |
133 | 0 | Ref::from_bytes(bytes).ok() |
134 | 0 | } |
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 | 0 | pub fn into_slice(self) -> &'a [T] { |
146 | 0 | Ref::into_ref(self) |
147 | 0 | } |
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 | 0 | pub fn into_mut_slice(self) -> &'a mut [T] { |
159 | 0 | Ref::into_mut(self) |
160 | 0 | } |
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 | 0 | pub fn new_slice_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> { |
173 | 0 | Ref::from_prefix_with_elems(bytes, count).ok() |
174 | 0 | } |
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 | 0 | pub fn new_slice_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> { |
181 | 0 | Ref::from_suffix_with_elems(bytes, count).ok() |
182 | 0 | } |
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 | 0 | pub fn new_slice_unaligned_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> { |
198 | 0 | Ref::from_prefix_with_elems(bytes, count).ok() |
199 | 0 | } |
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 | 0 | pub fn new_slice_unaligned_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> { |
209 | 0 | Ref::from_suffix_with_elems(bytes, count).ok() |
210 | 0 | } |
211 | | } |