Skip to content

Commit cd82ae7

Browse files
authored
Add non-slice Ref constructors w/ slice elem count (#996)
Add `Ref` constructors which are generic over `T: KnownLayout<PointerMetadata = usize>` - in other words, types whose trailing field is a slice (i.e., slices or slice DSTs). These constructors take an explicit element count for the trailing slice, and replace the previous constructors which only supported slices. Makes progress on #29
1 parent 243c452 commit cd82ae7

File tree

2 files changed

+207
-141
lines changed

2 files changed

+207
-141
lines changed

src/deprecated.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,53 @@ where
6363
self.into_mut()
6464
}
6565
}
66+
67+
impl<B, T> Ref<B, [T]>
68+
where
69+
B: SplitByteSlice,
70+
T: Immutable,
71+
{
72+
#[deprecated(since = "0.8.0", note = "replaced by `Ref::with_trailing_elements_from_prefix`")]
73+
#[must_use = "has no side effects"]
74+
#[doc(hidden)]
75+
#[inline]
76+
pub fn new_slice_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> {
77+
Ref::with_trailing_elements_from_prefix(bytes, count)
78+
}
79+
80+
#[deprecated(since = "0.8.0", note = "replaced by `Ref::with_trailing_elements_from_suffix`")]
81+
#[must_use = "has no side effects"]
82+
#[doc(hidden)]
83+
#[inline]
84+
pub fn new_slice_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> {
85+
Ref::with_trailing_elements_from_suffix(bytes, count)
86+
}
87+
}
88+
89+
impl<B, T> Ref<B, [T]>
90+
where
91+
B: SplitByteSlice,
92+
T: Unaligned + Immutable,
93+
{
94+
#[deprecated(
95+
since = "0.8.0",
96+
note = "replaced by `Ref::with_trailing_elements_unaligned_from_prefix`"
97+
)]
98+
#[doc(hidden)]
99+
#[must_use = "has no side effects"]
100+
#[inline(always)]
101+
pub fn new_slice_unaligned_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> {
102+
Ref::with_trailing_elements_unaligned_from_prefix(bytes, count)
103+
}
104+
105+
#[deprecated(
106+
since = "0.8.0",
107+
note = "replaced by `Ref::with_trailing_elements_unaligned_from_suffix`"
108+
)]
109+
#[doc(hidden)]
110+
#[must_use = "has no side effects"]
111+
#[inline(always)]
112+
pub fn new_slice_unaligned_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> {
113+
Ref::with_trailing_elements_unaligned_from_suffix(bytes, count)
114+
}
115+
}

0 commit comments

Comments
 (0)