Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4038ca0
Refactor tests of Write for Cursor<_>
cuviper Jan 8, 2022
a04d553
impl Write for Cursor<[u8; N]>
cuviper Jan 19, 2022
38cef65
Write for Cursor with a custom Allocator
cuviper Jan 20, 2022
6706ab8
keyword_docs: document use of `in` with `pub` keyword
mfrw Feb 6, 2022
d4686c6
Use verbatim paths for `process::Command` if necessary
ChrisDenton Jan 5, 2022
93f627d
Keep the path after `program_exists` succeeds
ChrisDenton Feb 17, 2022
ee02f01
Consistently present absent stdio handles on Windows as NULL handles.
sunfishcode Jan 21, 2022
7dd3246
Fix a compilation error.
sunfishcode Jan 25, 2022
7ddf41c
Remove redundant code for handling NULL handles on Windows.
sunfishcode Mar 2, 2022
7a74d28
fix return values in L4Re networking stub
humenda Jun 18, 2020
11b7176
fix return value of LookupHost::port()
humenda Dec 5, 2018
898f379
drop unused libc imports on L4Re
atopia May 31, 2021
c0dc41f
L4Re does not support sanitizing standard streams
atopia Jun 2, 2021
997dc58
adapt L4Re network interface mock to #87329
atopia Oct 18, 2021
cb013d4
put L4Re specifics into their own platform
atopia Oct 18, 2021
bc199b5
add as_raw() method to L4Re's Socket mock
atopia Jan 14, 2022
7d44316
Bump impl Write for Cursor<[u8; N]> to 1.61
dtolnay Mar 18, 2022
d5fe4ca
add CStr::from_bytes_until_nul
ericseppanen Mar 15, 2022
ba2d5ed
Rollup merge of #92519 - ChrisDenton:command-maybe-verbatim, r=dtolnay
Dylan-DPC Mar 19, 2022
a87590e
Rollup merge of #92612 - atopia:update-lib-l4re, r=dtolnay
Dylan-DPC Mar 19, 2022
e9f63fd
Rollup merge of #92663 - cuviper:generic-write-cursor, r=dtolnay
Dylan-DPC Mar 19, 2022
fe55eee
Rollup merge of #93263 - sunfishcode:sunfishcode/detatched-console-ha…
Dylan-DPC Mar 19, 2022
463e516
Rollup merge of #93692 - mfrw:mfrw/document-keyword-in, r=dtolnay
Dylan-DPC Mar 19, 2022
30b4182
Rollup merge of #94984 - ericseppanen:cstr_from_bytes, r=Mark-Simulacrum
Dylan-DPC Mar 19, 2022
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
Prev Previous commit
Next Next commit
Write for Cursor with a custom Allocator
  • Loading branch information
cuviper committed Jan 20, 2022
commit 38cef656d8df6e77630f923e2e8e20862adfc4e4
30 changes: 23 additions & 7 deletions library/std/src/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod tests;

use crate::io::prelude::*;

use crate::alloc::Allocator;
use crate::cmp;
use crate::io::{self, Error, ErrorKind, IoSlice, IoSliceMut, ReadBuf, SeekFrom};

Expand Down Expand Up @@ -398,7 +399,10 @@ fn slice_write_vectored(
}

// Resizing write implementation
fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usize> {
fn vec_write<A>(pos_mut: &mut u64, vec: &mut Vec<u8, A>, buf: &[u8]) -> io::Result<usize>
where
A: Allocator,
{
let pos: usize = (*pos_mut).try_into().map_err(|_| {
Error::new_const(
ErrorKind::InvalidInput,
Expand Down Expand Up @@ -426,11 +430,14 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usi
Ok(buf.len())
}

fn vec_write_vectored(
fn vec_write_vectored<A>(
pos_mut: &mut u64,
vec: &mut Vec<u8>,
vec: &mut Vec<u8, A>,
bufs: &[IoSlice<'_>],
) -> io::Result<usize> {
) -> io::Result<usize>
where
A: Allocator,
{
let mut nwritten = 0;
for buf in bufs {
nwritten += vec_write(pos_mut, vec, buf)?;
Expand Down Expand Up @@ -462,7 +469,10 @@ impl Write for Cursor<&mut [u8]> {
}

#[stable(feature = "cursor_mut_vec", since = "1.25.0")]
impl Write for Cursor<&mut Vec<u8>> {
impl<A> Write for Cursor<&mut Vec<u8, A>>
where
A: Allocator,
{
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
vec_write(&mut self.pos, self.inner, buf)
}
Expand All @@ -483,7 +493,10 @@ impl Write for Cursor<&mut Vec<u8>> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Write for Cursor<Vec<u8>> {
impl<A> Write for Cursor<Vec<u8, A>>
where
A: Allocator,
{
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
vec_write(&mut self.pos, &mut self.inner, buf)
}
Expand All @@ -504,7 +517,10 @@ impl Write for Cursor<Vec<u8>> {
}

#[stable(feature = "cursor_box_slice", since = "1.5.0")]
impl Write for Cursor<Box<[u8]>> {
impl<A> Write for Cursor<Box<[u8], A>>
where
A: Allocator,
{
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
slice_write(&mut self.pos, &mut self.inner, buf)
Expand Down