Skip to content

Commit

Permalink
Added implementations of AsRef and AsMut to ByteBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri6037 committed Nov 21, 2023
1 parent 34e45a8 commit 9c2bc08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bytesutil"
version = "0.3.0"
version = "0.4.0"
authors = ["Yuri Edward <yuri6037@outlook.com>"]
edition = "2021"
description = "Yet another byte utility for Rust"
Expand Down
12 changes: 12 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ impl<T: AsRef<[u8]>> ByteBuf<T> {
}
}

impl<T: AsRef<[u8]>> AsRef<[u8]> for ByteBuf<T> {
fn as_ref(&self) -> &[u8] {
self.inner.as_ref()
}
}

impl<T: AsMut<[u8]>> ByteBuf<T> {
/// Write the given little-endian `value` field at the given `pos` offset in bytes.
pub fn set_le<V: WriteBytes>(&mut self, pos: usize, value: V) -> &mut Self {
Expand All @@ -61,6 +67,12 @@ impl<T: AsMut<[u8]>> ByteBuf<T> {
}
}

impl<T: AsMut<[u8]>> AsMut<[u8]> for ByteBuf<T> {
fn as_mut(&mut self) -> &mut [u8] {
self.inner.as_mut()
}
}

impl<T> ByteBuf<T> {
/// Allocates a new ByteBuf by wrapping the given bytes-like object.
///
Expand Down

0 comments on commit 9c2bc08

Please sign in to comment.