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 committed Apr 23, 2024
1 parent 435feb4 commit 2321483
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 139 deletions.
50 changes: 50 additions & 0 deletions src/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,53 @@ where
self.into_mut()
}
}

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`")]
#[must_use = "has no side effects"]
#[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`")]
#[must_use = "has no side effects"]
#[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: SplitByteSlice,
T: Unaligned + NoCell,
{
#[deprecated(
since = "0.8.0",
note = "replaced by `Ref::with_trailing_elements_unaligned_from_prefix`"
)]
#[doc(hidden)]
#[must_use = "has no side effects"]
#[inline(always)]
pub fn new_slice_unaligned_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> {
Ref::with_trailing_elements_unaligned_from_prefix(bytes, count)
}

#[deprecated(
since = "0.8.0",
note = "replaced by `Ref::with_trailing_elements_unaligned_from_suffix`"
)]
#[doc(hidden)]
#[must_use = "has no side effects"]
#[inline(always)]
pub fn new_slice_unaligned_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> {
Ref::with_trailing_elements_unaligned_from_suffix(bytes, count)
}
}
Loading

0 comments on commit 2321483

Please sign in to comment.