Skip to content

Commit

Permalink
Implement Write for Vec<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Mar 21, 2024
1 parent afbe7da commit 431c0b4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions rt/src/io/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,45 @@ impl Write for &mut [u8] {
}
}

impl Write for Vec<u8> {
async fn write<B: Buf>(&mut self, buf: B) -> io::Result<(B, usize)> {
self.extend_from_slice(buf.as_slice());
let written = buf.len();
Ok((buf, written))
}

async fn write_all<B: Buf>(&mut self, buf: B) -> io::Result<B> {
self.extend_from_slice(buf.as_slice());
Ok(buf)
}

fn is_write_vectored(&self) -> bool {
false
}

async fn write_vectored<B: BufSlice<N>, const N: usize>(
&mut self,
bufs: B,
) -> io::Result<(B, usize)> {
let mut written = 0;
for buf in bufs.as_io_slices() {
self.extend_from_slice(&buf);
written += buf.len();
}
Ok((bufs, written))
}

async fn write_vectored_all<B: BufSlice<N>, const N: usize>(
&mut self,
bufs: B,
) -> io::Result<B> {
for buf in bufs.as_io_slices() {
self.extend_from_slice(&buf);
}
Ok(bufs)
}
}

impl Write for Sink {
async fn write<B: Buf>(&mut self, buf: B) -> io::Result<(B, usize)> {
let len = buf.len();
Expand Down

0 comments on commit 431c0b4

Please sign in to comment.