Skip to content

Commit

Permalink
octets: fix incorrect lifetime annotation
Browse files Browse the repository at this point in the history
The lifetime of the returned reference of the slice() and slice_last() methods was bounded by the lifetime of the method's receiver.
The methods in question return a subslice of a field stored inside the
receiver, whose lifetime may differ from that of the the method's receiver.
As such, the lifetime of the returned value should be bound to the lifetime of the receiver's field.
  • Loading branch information
vhein99 authored Jan 22, 2024
1 parent dfeaa58 commit 21704e0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions octets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<'a> Octets<'a> {
}

/// Returns a slice of `len` elements from the current offset.
pub fn slice(&'a self, len: usize) -> Result<&'a [u8]> {
pub fn slice(&self, len: usize) -> Result<&'a [u8]> {
if len > self.cap() {
return Err(BufferTooShortError);
}
Expand All @@ -260,7 +260,7 @@ impl<'a> Octets<'a> {
}

/// Returns a slice of `len` elements from the end of the buffer.
pub fn slice_last(&'a self, len: usize) -> Result<&'a [u8]> {
pub fn slice_last(&self, len: usize) -> Result<&'a [u8]> {
if len > self.cap() {
return Err(BufferTooShortError);
}
Expand Down

0 comments on commit 21704e0

Please sign in to comment.