Skip to content

Commit

Permalink
Add non-slice Ref constructors w/ slice elem count
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joshlf authored and jswrenn committed Apr 18, 2024
1 parent bfbf7f3 commit c4dce00
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 129 deletions.
46 changes: 46 additions & 0 deletions src/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,52 @@ where
}
}

impl<B, T> Ref<B, [T]>
where
B: SplitByteSlice,
T: NoCell,
{
#[deprecated(since = "0.8.0", note = "replaced by `Ref::with_trailing_elements_from_prefix`")]
#[doc(hidden)]
#[inline]
pub fn new_slice_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> {
Ref::with_trailing_elements_from_prefix(bytes, count)
}

#[deprecated(since = "0.8.0", note = "replaced by `Ref::with_trailing_elements_from_suffix`")]
#[doc(hidden)]
#[inline]
pub fn new_slice_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> {
Ref::with_trailing_elements_from_suffix(bytes, count)
}
}

impl<B, T> Ref<B, [T]>
where
B: SplitByteSliceMut,
T: NoCell,
{
#[deprecated(
since = "0.8.0",
note = "replaced by `Ref::with_trailing_elements_from_prefix_zeroed`"
)]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_from_prefix_zeroed(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> {
Self::with_trailing_elements_from_prefix_zeroed(bytes, count)
}

#[deprecated(
since = "0.8.0",
note = "replaced by `Ref::with_trailing_elements_from_suffix_zeroed`"
)]
#[doc(hidden)]
#[inline(always)]
pub fn new_slice_from_suffix_zeroed(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> {
Self::with_trailing_elements_from_suffix_zeroed(bytes, count)
}
}

impl<'a, B, T> Ref<B, [T]>
where
B: 'a + IntoByteSlice<'a>,
Expand Down
Loading

0 comments on commit c4dce00

Please sign in to comment.