Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3803c09
Rename IoSlice(Mut)::advance to advance_slice
Thomasdezeeuw May 29, 2021
49e25b5
Add IoSlice(Mut)::advance
Thomasdezeeuw May 29, 2021
fd14c52
Rename IoSlice(Mut)::advance_slice to advance_slices
Thomasdezeeuw Jun 5, 2021
2727c3b
Document Arc::from
fee1-dead May 25, 2021
4fe4ff9
Use better error message for hard errors in CTFE
syvb Jun 15, 2021
c8a8a23
Do not emit invalid suggestions on multiple mutable borrow errors
JohnTitor Jun 16, 2021
d828ead
Remove invalid suggestions for assoc consts on placeholder type error
JohnTitor Jun 16, 2021
fb06d9e
Move some typeck-related tests to the typeck dir
JohnTitor Jun 16, 2021
044b362
Move some hard error logic to InterpError
syvb Jun 16, 2021
cb2f8d9
Make `sum()` and `product()` hyperlinks refer to `Iterator` methods.
kpreid Jun 17, 2021
ce64729
Remove methods under Implementors on trait pages
jsha Jun 3, 2021
bff4f07
Use render_impl_summary when rendering traits.
jsha Jun 8, 2021
910c7fa
Add doc(hidden) to all __iterator_get_unchecked
jsha Jun 12, 2021
593d6d1
Make portability part of the summary.
jsha Jun 8, 2021
5de1391
Factor out render_rightside
jsha Jun 12, 2021
c4fa6d5
Move anchor earlier in the DOM for easier layout
jsha Jun 17, 2021
2ac5c17
Fix target highlighting in rustdoc.
jsha Jun 17, 2021
bf81e13
Restore details for Impls on Foreign Types
jsha Jun 16, 2021
5e7a8c6
Fix typos in code examples.
m-ou-se Jun 17, 2021
36b9a6e
Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-se
JohnTitor Jun 17, 2021
31ee680
Rollup merge of #85802 - Thomasdezeeuw:ioslice-advance, r=m-ou-se
JohnTitor Jun 17, 2021
9521da7
Rollup merge of #85970 - jsha:remove-methods-implementors, r=Guillaum…
JohnTitor Jun 17, 2021
c062f3d
Rollup merge of #86340 - Smittyvb:ctfe-hard-error-message, r=RalfJung
JohnTitor Jun 17, 2021
afe70ee
Rollup merge of #86343 - JohnTitor:issue-85581, r=estebank
JohnTitor Jun 17, 2021
aff7994
Rollup merge of #86355 - JohnTitor:issue-82158, r=estebank
JohnTitor Jun 17, 2021
65d412b
Rollup merge of #86389 - kpreid:sum, r=scottmcm
JohnTitor Jun 17, 2021
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 63 additions & 12 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ mod tests;

use crate::cmp;
use crate::fmt;
use crate::mem::replace;
use crate::ops::{Deref, DerefMut};
use crate::ptr;
use crate::slice;
Expand Down Expand Up @@ -1044,6 +1045,32 @@ impl<'a> IoSliceMut<'a> {

/// Advance the internal cursor of the slice.
///
/// Also see [`IoSliceMut::advance_slices`] to advance the cursors of
/// multiple buffers.
///
/// # Examples
///
/// ```
/// #![feature(io_slice_advance)]
///
/// use std::io::IoSliceMut;
/// use std::ops::Deref;
///
/// let mut data = [1; 8];
/// let mut buf = IoSliceMut::new(&mut data);
///
/// // Mark 3 bytes as read.
/// buf.advance(3);
/// assert_eq!(buf.deref(), [1; 5].as_ref());
/// ```
#[unstable(feature = "io_slice_advance", issue = "62726")]
#[inline]
pub fn advance(&mut self, n: usize) {
self.0.advance(n)
}

/// Advance the internal cursor of the slices.
///
/// # Notes
///
/// Elements in the slice may be modified if the cursor is not advanced to
Expand All @@ -1070,13 +1097,13 @@ impl<'a> IoSliceMut<'a> {
/// ][..];
///
/// // Mark 10 bytes as read.
/// bufs = IoSliceMut::advance(bufs, 10);
/// IoSliceMut::advance_slices(&mut bufs, 10);
/// assert_eq!(bufs[0].deref(), [2; 14].as_ref());
/// assert_eq!(bufs[1].deref(), [3; 8].as_ref());
/// ```
#[unstable(feature = "io_slice_advance", issue = "62726")]
#[inline]
pub fn advance<'b>(bufs: &'b mut [IoSliceMut<'a>], n: usize) -> &'b mut [IoSliceMut<'a>] {
pub fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize) {
// Number of buffers to remove.
let mut remove = 0;
// Total length of all the to be removed buffers.
Expand All @@ -1090,11 +1117,10 @@ impl<'a> IoSliceMut<'a> {
}
}

let bufs = &mut bufs[remove..];
*bufs = &mut replace(bufs, &mut [])[remove..];
if !bufs.is_empty() {
bufs[0].0.advance(n - accumulated_len)
bufs[0].advance(n - accumulated_len)
}
bufs
}
}

Expand Down Expand Up @@ -1153,6 +1179,32 @@ impl<'a> IoSlice<'a> {

/// Advance the internal cursor of the slice.
///
/// Also see [`IoSlice::advance_slices`] to advance the cursors of multiple
/// buffers.
///
/// # Examples
///
/// ```
/// #![feature(io_slice_advance)]
///
/// use std::io::IoSlice;
/// use std::ops::Deref;
///
/// let mut data = [1; 8];
/// let mut buf = IoSlice::new(&mut data);
///
/// // Mark 3 bytes as read.
/// buf.advance(3);
/// assert_eq!(buf.deref(), [1; 5].as_ref());
/// ```
#[unstable(feature = "io_slice_advance", issue = "62726")]
#[inline]
pub fn advance(&mut self, n: usize) {
self.0.advance(n)
}

/// Advance the internal cursor of the slices.
///
/// # Notes
///
/// Elements in the slice may be modified if the cursor is not advanced to
Expand All @@ -1179,12 +1231,12 @@ impl<'a> IoSlice<'a> {
/// ][..];
///
/// // Mark 10 bytes as written.
/// bufs = IoSlice::advance(bufs, 10);
/// IoSlice::advance_slices(&mut bufs, 10);
/// assert_eq!(bufs[0].deref(), [2; 14].as_ref());
/// assert_eq!(bufs[1].deref(), [3; 8].as_ref());
#[unstable(feature = "io_slice_advance", issue = "62726")]
#[inline]
pub fn advance<'b>(bufs: &'b mut [IoSlice<'a>], n: usize) -> &'b mut [IoSlice<'a>] {
pub fn advance_slices(bufs: &mut &mut [IoSlice<'a>], n: usize) {
// Number of buffers to remove.
let mut remove = 0;
// Total length of all the to be removed buffers.
Expand All @@ -1198,11 +1250,10 @@ impl<'a> IoSlice<'a> {
}
}

let bufs = &mut bufs[remove..];
*bufs = &mut replace(bufs, &mut [])[remove..];
if !bufs.is_empty() {
bufs[0].0.advance(n - accumulated_len)
bufs[0].advance(n - accumulated_len)
}
bufs
}
}

Expand Down Expand Up @@ -1511,7 +1562,7 @@ pub trait Write {
fn write_all_vectored(&mut self, mut bufs: &mut [IoSlice<'_>]) -> Result<()> {
// Guarantee that bufs is empty if it contains no data,
// to avoid calling write_vectored if there is no data to be written.
bufs = IoSlice::advance(bufs, 0);
IoSlice::advance_slices(&mut bufs, 0);
while !bufs.is_empty() {
match self.write_vectored(bufs) {
Ok(0) => {
Expand All @@ -1520,7 +1571,7 @@ pub trait Write {
&"failed to write whole buffer",
));
}
Ok(n) => bufs = IoSlice::advance(bufs, n),
Ok(n) => IoSlice::advance_slices(&mut bufs, n),
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
Expand Down
36 changes: 18 additions & 18 deletions library/std/src/io/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fn test_read_to_end_capacity() -> io::Result<()> {
}

#[test]
fn io_slice_mut_advance() {
fn io_slice_mut_advance_slices() {
let mut buf1 = [1; 8];
let mut buf2 = [2; 16];
let mut buf3 = [3; 8];
Expand All @@ -364,75 +364,75 @@ fn io_slice_mut_advance() {
][..];

// Only in a single buffer..
bufs = IoSliceMut::advance(bufs, 1);
IoSliceMut::advance_slices(&mut bufs, 1);
assert_eq!(bufs[0].deref(), [1; 7].as_ref());
assert_eq!(bufs[1].deref(), [2; 16].as_ref());
assert_eq!(bufs[2].deref(), [3; 8].as_ref());

// Removing a buffer, leaving others as is.
bufs = IoSliceMut::advance(bufs, 7);
IoSliceMut::advance_slices(&mut bufs, 7);
assert_eq!(bufs[0].deref(), [2; 16].as_ref());
assert_eq!(bufs[1].deref(), [3; 8].as_ref());

// Removing a buffer and removing from the next buffer.
bufs = IoSliceMut::advance(bufs, 18);
IoSliceMut::advance_slices(&mut bufs, 18);
assert_eq!(bufs[0].deref(), [3; 6].as_ref());
}

#[test]
fn io_slice_mut_advance_empty_slice() {
let empty_bufs = &mut [][..];
fn io_slice_mut_advance_slices_empty_slice() {
let mut empty_bufs = &mut [][..];
// Shouldn't panic.
IoSliceMut::advance(empty_bufs, 1);
IoSliceMut::advance_slices(&mut empty_bufs, 1);
}

#[test]
fn io_slice_mut_advance_beyond_total_length() {
fn io_slice_mut_advance_slices_beyond_total_length() {
let mut buf1 = [1; 8];
let mut bufs = &mut [IoSliceMut::new(&mut buf1)][..];

// Going beyond the total length should be ok.
bufs = IoSliceMut::advance(bufs, 9);
IoSliceMut::advance_slices(&mut bufs, 9);
assert!(bufs.is_empty());
}

#[test]
fn io_slice_advance() {
fn io_slice_advance_slices() {
let buf1 = [1; 8];
let buf2 = [2; 16];
let buf3 = [3; 8];
let mut bufs = &mut [IoSlice::new(&buf1), IoSlice::new(&buf2), IoSlice::new(&buf3)][..];

// Only in a single buffer..
bufs = IoSlice::advance(bufs, 1);
IoSlice::advance_slices(&mut bufs, 1);
assert_eq!(bufs[0].deref(), [1; 7].as_ref());
assert_eq!(bufs[1].deref(), [2; 16].as_ref());
assert_eq!(bufs[2].deref(), [3; 8].as_ref());

// Removing a buffer, leaving others as is.
bufs = IoSlice::advance(bufs, 7);
IoSlice::advance_slices(&mut bufs, 7);
assert_eq!(bufs[0].deref(), [2; 16].as_ref());
assert_eq!(bufs[1].deref(), [3; 8].as_ref());

// Removing a buffer and removing from the next buffer.
bufs = IoSlice::advance(bufs, 18);
IoSlice::advance_slices(&mut bufs, 18);
assert_eq!(bufs[0].deref(), [3; 6].as_ref());
}

#[test]
fn io_slice_advance_empty_slice() {
let empty_bufs = &mut [][..];
fn io_slice_advance_slices_empty_slice() {
let mut empty_bufs = &mut [][..];
// Shouldn't panic.
IoSlice::advance(empty_bufs, 1);
IoSlice::advance_slices(&mut empty_bufs, 1);
}

#[test]
fn io_slice_advance_beyond_total_length() {
fn io_slice_advance_slices_beyond_total_length() {
let buf1 = [1; 8];
let mut bufs = &mut [IoSlice::new(&buf1)][..];

// Going beyond the total length should be ok.
bufs = IoSlice::advance(bufs, 9);
IoSlice::advance_slices(&mut bufs, 9);
assert!(bufs.is_empty());
}

Expand Down