Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,12 @@ mod tests {
let slice = Slice::from_reader(&mut reader, 4).expect("read");
assert_eq!(slice, vec![1, 2, 3, 4]);
}

/// Verifies that `Slice::as_slice` returns the data as-is.
#[test]
fn test_slice_as_slice() {
let original = [1_u8, 2, 3, 4];
let slice = Slice::from_iter(original.iter().copied());
assert_eq!(slice.as_slice(), original);
}
}
6 changes: 6 additions & 0 deletions src/slice/slice_bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ impl Slice {
Self(Bytes::copy_from_slice(bytes))
}

/// Returns the bytes slice containing the entire data.
#[must_use]
pub fn as_slice(&self) -> &[u8] {
self
}

#[doc(hidden)]
#[must_use]
pub fn empty() -> Self {
Expand Down
6 changes: 6 additions & 0 deletions src/slice/slice_default/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ impl Slice {
Self(bytes.into())
}

/// Returns the bytes slice containing the entire data.
#[must_use]
pub fn as_slice(&self) -> &[u8] {
self
}

Comment thread
irevoire marked this conversation as resolved.
#[doc(hidden)]
#[must_use]
pub fn empty() -> Self {
Expand Down