Skip to content

Commit

Permalink
docs(primitives): report some Bytes methods may panic (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb authored Feb 18, 2025
1 parent cabccd6 commit aa80b5a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/primitives/src/bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,25 +315,43 @@ impl Bytes {
}

/// Returns a slice of self for the provided range.
///
/// # Panics
///
/// Requires that `begin <= end` and `end <= self.len()`, otherwise slicing
/// will panic.
#[inline]
pub fn slice(&self, range: impl RangeBounds<usize>) -> Self {
Self(self.0.slice(range))
}

/// Returns a slice of self that is equivalent to the given `subset`.
///
/// # Panics
///
/// Requires that the given `subset` slice is in fact contained within the
/// `Bytes` buffer; otherwise this function will panic.
#[inline]
pub fn slice_ref(&self, subset: &[u8]) -> Self {
Self(self.0.slice_ref(subset))
}

/// Splits the bytes into two at the given index.
///
/// # Panics
///
/// Panics if `at > len`.
#[must_use = "consider Bytes::truncate if you don't need the other half"]
#[inline]
pub fn split_off(&mut self, at: usize) -> Self {
Self(self.0.split_off(at))
}

/// Splits the bytes into two at the given index.
///
/// # Panics
///
/// Panics if `at > len`.
#[must_use = "consider Bytes::advance if you don't need the other half"]
#[inline]
pub fn split_to(&mut self, at: usize) -> Self {
Expand Down

0 comments on commit aa80b5a

Please sign in to comment.