Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: replace split_to and split_off with better alternatives #807

Merged
merged 1 commit into from
Nov 3, 2024
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
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