Skip to content

Commit 38cef65

Browse files
committed
Write for Cursor with a custom Allocator
1 parent a04d553 commit 38cef65

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

library/std/src/io/cursor.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod tests;
33

44
use crate::io::prelude::*;
55

6+
use crate::alloc::Allocator;
67
use crate::cmp;
78
use crate::io::{self, Error, ErrorKind, IoSlice, IoSliceMut, ReadBuf, SeekFrom};
89

@@ -398,7 +399,10 @@ fn slice_write_vectored(
398399
}
399400

400401
// Resizing write implementation
401-
fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usize> {
402+
fn vec_write<A>(pos_mut: &mut u64, vec: &mut Vec<u8, A>, buf: &[u8]) -> io::Result<usize>
403+
where
404+
A: Allocator,
405+
{
402406
let pos: usize = (*pos_mut).try_into().map_err(|_| {
403407
Error::new_const(
404408
ErrorKind::InvalidInput,
@@ -426,11 +430,14 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usi
426430
Ok(buf.len())
427431
}
428432

429-
fn vec_write_vectored(
433+
fn vec_write_vectored<A>(
430434
pos_mut: &mut u64,
431-
vec: &mut Vec<u8>,
435+
vec: &mut Vec<u8, A>,
432436
bufs: &[IoSlice<'_>],
433-
) -> io::Result<usize> {
437+
) -> io::Result<usize>
438+
where
439+
A: Allocator,
440+
{
434441
let mut nwritten = 0;
435442
for buf in bufs {
436443
nwritten += vec_write(pos_mut, vec, buf)?;
@@ -462,7 +469,10 @@ impl Write for Cursor<&mut [u8]> {
462469
}
463470

464471
#[stable(feature = "cursor_mut_vec", since = "1.25.0")]
465-
impl Write for Cursor<&mut Vec<u8>> {
472+
impl<A> Write for Cursor<&mut Vec<u8, A>>
473+
where
474+
A: Allocator,
475+
{
466476
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
467477
vec_write(&mut self.pos, self.inner, buf)
468478
}
@@ -483,7 +493,10 @@ impl Write for Cursor<&mut Vec<u8>> {
483493
}
484494

485495
#[stable(feature = "rust1", since = "1.0.0")]
486-
impl Write for Cursor<Vec<u8>> {
496+
impl<A> Write for Cursor<Vec<u8, A>>
497+
where
498+
A: Allocator,
499+
{
487500
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
488501
vec_write(&mut self.pos, &mut self.inner, buf)
489502
}
@@ -504,7 +517,10 @@ impl Write for Cursor<Vec<u8>> {
504517
}
505518

506519
#[stable(feature = "cursor_box_slice", since = "1.5.0")]
507-
impl Write for Cursor<Box<[u8]>> {
520+
impl<A> Write for Cursor<Box<[u8], A>>
521+
where
522+
A: Allocator,
523+
{
508524
#[inline]
509525
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
510526
slice_write(&mut self.pos, &mut self.inner, buf)

0 commit comments

Comments
 (0)