Skip to content

Commit

Permalink
style: replace split_to and split_off with better alternatives
Browse files Browse the repository at this point in the history
This removes `let _ = ` from in front of `split_to` and `split_off`
and mostly follows the suggestions from the `#[must_use]` impls.
One of the uses of `split_to` is instead replaced with `take`.
  • Loading branch information
paolobarbolini authored and seanmonstar committed Nov 3, 2024
1 parent 77be664 commit 4d66d5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/codec/framed_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::hpack;

use futures_core::Stream;

use bytes::BytesMut;
use bytes::{Buf, BytesMut};

use std::io;

Expand Down Expand Up @@ -146,8 +146,7 @@ fn decode_frame(
macro_rules! header_block {
($frame:ident, $head:ident, $bytes:ident) => ({
// Drop the frame header
// TODO: Change to drain: carllerche/bytes#130
let _ = $bytes.split_to(frame::HEADER_LEN);
$bytes.advance(frame::HEADER_LEN);

// Parse the header frame w/o parsing the payload
let (mut frame, mut payload) = match frame::$frame::load($head, $bytes) {
Expand Down Expand Up @@ -227,7 +226,7 @@ fn decode_frame(
.into()
}
Kind::Data => {
let _ = bytes.split_to(frame::HEADER_LEN);
bytes.advance(frame::HEADER_LEN);
let res = frame::Data::load(head, bytes.freeze());

// TODO: Should this always be connection level? Probably not...
Expand Down
12 changes: 6 additions & 6 deletions src/frame/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::hpack::{self, BytesStr};
use http::header::{self, HeaderName, HeaderValue};
use http::{uri, HeaderMap, Method, Request, StatusCode, Uri};

use bytes::{BufMut, Bytes, BytesMut};
use bytes::{Buf, BufMut, Bytes, BytesMut};

use std::fmt;
use std::io::Cursor;
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Headers {
pad = src[0] as usize;

// Drop the padding
let _ = src.split_to(1);
src.advance(1);
}

// Read the stream dependency
Expand All @@ -181,7 +181,7 @@ impl Headers {
}

// Drop the next 5 bytes
let _ = src.split_to(5);
src.advance(5);

Some(stream_dep)
} else {
Expand Down Expand Up @@ -425,7 +425,7 @@ impl PushPromise {
pad = src[0] as usize;

// Drop the padding
let _ = src.split_to(1);
src.advance(1);
}

if src.len() < 5 {
Expand All @@ -434,7 +434,7 @@ impl PushPromise {

let (promised_id, _) = StreamId::parse(&src[..4]);
// Drop promised_id bytes
let _ = src.split_to(4);
src.advance(4);

if pad > 0 {
if pad > src.len() {
Expand Down Expand Up @@ -657,7 +657,7 @@ impl EncodingHeaderBlock {

// Now, encode the header payload
let continuation = if self.hpack.len() > dst.remaining_mut() {
dst.put_slice(&self.hpack.split_to(dst.remaining_mut()));
dst.put((&mut self.hpack).take(dst.remaining_mut()));

Some(Continuation {
stream_id: head.stream_id(),
Expand Down
6 changes: 3 additions & 3 deletions src/frame/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use super::Error;
use bytes::Bytes;
use bytes::{Buf, Bytes};

/// Strip padding from the given payload.
///
Expand Down Expand Up @@ -32,8 +32,8 @@ pub fn strip_padding(payload: &mut Bytes) -> Result<u8, Error> {
return Err(Error::TooMuchPadding);
}

let _ = payload.split_to(1);
let _ = payload.split_off(payload_len - pad_len - 1);
payload.advance(1);
payload.truncate(payload_len - pad_len - 1);

Ok(pad_len as u8)
}
Expand Down

0 comments on commit 4d66d5d

Please sign in to comment.