[Crate] Apply strict clippy on buffer

This commit is contained in:
CosminPerRam 2023-08-06 21:54:19 +03:00
parent 4ff50ea711
commit 5aa2ce99ec

View file

@ -29,7 +29,7 @@ impl<'a, B: ByteOrder> Buffer<'a, B> {
/// # Arguments /// # Arguments
/// ///
/// * `data` - A byte slice that the buffer will read from. /// * `data` - A byte slice that the buffer will read from.
pub(crate) fn new(data: &'a [u8]) -> Self { pub(crate) const fn new(data: &'a [u8]) -> Self {
Self { Self {
data, data,
cursor: 0, cursor: 0,
@ -37,14 +37,14 @@ impl<'a, B: ByteOrder> Buffer<'a, B> {
} }
} }
pub(crate) fn current_position(&self) -> usize { self.cursor } pub(crate) const fn current_position(&self) -> usize { self.cursor }
/// Returns the length of the remaining bytes from the current cursor /// Returns the length of the remaining bytes from the current cursor
/// position. /// position.
pub(crate) fn remaining_length(&self) -> usize { self.data.len() - self.cursor } pub(crate) const fn remaining_length(&self) -> usize { self.data.len() - self.cursor }
/// Returns the length of the buffer data. /// Returns the length of the buffer data.
pub(crate) fn data_length(&self) -> usize { self.data.len() } pub(crate) const fn data_length(&self) -> usize { self.data.len() }
// Added for legacy support just for the refactoring // Added for legacy support just for the refactoring
// Not Tested // Not Tested
@ -109,8 +109,7 @@ impl<'a, B: ByteOrder> Buffer<'a, B> {
// because we don't have enough data left to read. // because we don't have enough data left to read.
if size > remaining { if size > remaining {
return Err(PacketUnderflow.context(format!( return Err(PacketUnderflow.context(format!(
"Size requested {} was larger than remaining bytes {}", "Size requested {size} was larger than remaining bytes {remaining}"
size, remaining
))); )));
} }