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

unsafe impl<'a> BufMut for ReadBuf<'a> #5590

Merged
merged 19 commits into from
Apr 4, 2023
15 changes: 15 additions & 0 deletions tokio/src/io/read_buf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bytes::{buf::UninitSlice, BufMut};
use std::fmt;
use std::mem::MaybeUninit;

Expand Down Expand Up @@ -270,6 +271,20 @@ impl<'a> ReadBuf<'a> {
}
}

unsafe impl<'a> BufMut for ReadBuf<'a> {
amab8901 marked this conversation as resolved.
Show resolved Hide resolved
fn remaining_mut(&self) -> usize {
self.remaining()
}

unsafe fn advance_mut(&mut self, cnt: usize) {
self.advance(cnt);
}

fn chunk_mut(&mut self) -> &mut UninitSlice {
unsafe { UninitSlice::from_raw_parts_mut(10 as *mut u8, 10) }
amab8901 marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl fmt::Debug for ReadBuf<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ReadBuf")
Expand Down