pub struct IoSliceMut<'a>(/* private fields */);alloc_io #154046)Expand description
A buffer type used with Read::read_vectored.
It is semantically a wrapper around a &mut [u8], but is guaranteed to be
ABI compatible with the iovec type on Unix platforms and WSABUF on
Windows.
Implementations§
Source§impl<'a> IoSliceMut<'a>
impl<'a> IoSliceMut<'a>
1.36.0 · Sourcepub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a>
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a>
Creates a new IoSliceMut wrapping a byte slice.
§Panics
Panics on Windows if the slice is larger than 4GB.
1.81.0 · Sourcepub fn advance(&mut self, n: usize)
pub fn advance(&mut self, n: usize)
Advance the internal cursor of the slice.
Also see IoSliceMut::advance_slices to advance the cursors of
multiple buffers.
§Panics
Panics when trying to advance beyond the end of the slice.
§Examples
1.81.0 · Sourcepub fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize)
pub fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize)
Advance a slice of slices.
Shrinks the slice to remove any IoSliceMuts that are fully advanced over.
If the cursor ends up in the middle of an IoSliceMut, it is modified
to start at that cursor.
For example, if we have a slice of two 8-byte IoSliceMuts, and we advance by 10 bytes,
the result will only include the second IoSliceMut, advanced by 2 bytes.
§Panics
Panics when trying to advance beyond the end of the slices.
§Examples
use std::io::IoSliceMut;
use std::ops::Deref;
let mut buf1 = [1; 8];
let mut buf2 = [2; 16];
let mut buf3 = [3; 8];
let mut bufs = &mut [
IoSliceMut::new(&mut buf1),
IoSliceMut::new(&mut buf2),
IoSliceMut::new(&mut buf3),
][..];
// Mark 10 bytes as read.
IoSliceMut::advance_slices(&mut bufs, 10);
assert_eq!(bufs[0].deref(), [2; 14].as_ref());
assert_eq!(bufs[1].deref(), [3; 8].as_ref());Sourcepub const fn into_slice(self) -> &'a mut [u8]
🔬This is a nightly-only experimental API. (io_slice_as_bytes #132818)
pub const fn into_slice(self) -> &'a mut [u8]
io_slice_as_bytes #132818)Get the underlying bytes as a mutable slice with the original lifetime.
§Examples
Methods from Deref<Target = [u8]>§
1.0.0 · Sourcepub fn sort(&mut self)where
T: Ord,
pub fn sort(&mut self)where
T: Ord,
Sorts the slice in ascending order, preserving initial order of equal elements.
This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case.
If the implementation of Ord for T does not implement a total order, the function
may panic; even if the function exits normally, the resulting order of elements in the slice
is unspecified. See also the note on panicking below.
When applicable, unstable sorting is preferred because it is generally faster than stable
sorting and it doesn’t allocate auxiliary memory. See
sort_unstable. The exception are partially sorted slices, which
may be better served with slice::sort.
Sorting types that only implement PartialOrd such as f32 and f64 require
additional precautions. For example, f32::NAN != f32::NAN, which doesn’t fulfill the
reflexivity requirement of Ord. By using an alternative comparison function with
slice::sort_by such as f32::total_cmp or f64::total_cmp that defines a total
order users can sort slices containing floating-point values. Alternatively, if all values
in the slice are guaranteed to be in a subset for which PartialOrd::partial_cmp forms a
total order, it’s possible to sort the slice with sort_by(|a, b| a.partial_cmp(b).unwrap()).
§Current implementation
The current implementation is based on driftsort by Orson Peters and Lukas Bergdoll, which combines the fast average case of quicksort with the fast worst case and partial run detection of mergesort, achieving linear time on fully sorted and reversed inputs. On inputs with k distinct elements, the expected time to sort the data is O(n * log(k)).
The auxiliary memory allocation behavior depends on the input length. Short slices are
handled without allocation, medium sized slices allocate self.len() and beyond that it
clamps at self.len() / 2.
§Panics
May panic if the implementation of Ord for T does not implement a total order, or if
the Ord implementation itself panics.
All safe functions on slices preserve the invariant that even if the function panics, all
original elements will remain in the slice and any possible modifications via interior
mutability are observed in the input. This ensures that recovery code (for instance inside
of a Drop or following a catch_unwind) will still have access to all the original
elements. For instance, if the slice belongs to a Vec, the Vec::drop method will be able
to dispose of all contained elements.
§Examples
1.0.0 · Sourcepub fn sort_by<F>(&mut self, compare: F)
pub fn sort_by<F>(&mut self, compare: F)
Sorts the slice in ascending order with a comparison function, preserving initial order of equal elements.
This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case.
If the comparison function compare does not implement a total order, the function may
panic; even if the function exits normally, the resulting order of elements in the slice is
unspecified. See also the note on panicking below.
For example |a, b| (a - b).cmp(a) is a comparison function that is neither transitive nor
reflexive nor total, a < b < c < a with a = 1, b = 2, c = 3. For more information and
examples see the Ord documentation.
§Current implementation
The current implementation is based on driftsort by Orson Peters and Lukas Bergdoll, which combines the fast average case of quicksort with the fast worst case and partial run detection of mergesort, achieving linear time on fully sorted and reversed inputs. On inputs with k distinct elements, the expected time to sort the data is O(n * log(k)).
The auxiliary memory allocation behavior depends on the input length. Short slices are
handled without allocation, medium sized slices allocate self.len() and beyond that it
clamps at self.len() / 2.
§Panics
May panic if compare does not implement a total order, or if compare itself panics.
All safe functions on slices preserve the invariant that even if the function panics, all
original elements will remain in the slice and any possible modifications via interior
mutability are observed in the input. This ensures that recovery code (for instance inside
of a Drop or following a catch_unwind) will still have access to all the original
elements. For instance, if the slice belongs to a Vec, the Vec::drop method will be able
to dispose of all contained elements.
§Examples
1.7.0 · Sourcepub fn sort_by_key<K, F>(&mut self, f: F)
pub fn sort_by_key<K, F>(&mut self, f: F)
Sorts the slice in ascending order with a key extraction function, preserving initial order of equal elements.
This sort is stable (i.e., does not reorder equal elements) and O(m * n * log(n)) worst-case, where the key function is O(m).
If the implementation of Ord for K does not implement a total order, the function
may panic; even if the function exits normally, the resulting order of elements in the slice
is unspecified. See also the note on panicking below.
§Current implementation
The current implementation is based on driftsort by Orson Peters and Lukas Bergdoll, which combines the fast average case of quicksort with the fast worst case and partial run detection of mergesort, achieving linear time on fully sorted and reversed inputs. On inputs with k distinct elements, the expected time to sort the data is O(n * log(k)).
The auxiliary memory allocation behavior depends on the input length. Short slices are
handled without allocation, medium sized slices allocate self.len() and beyond that it
clamps at self.len() / 2.
§Panics
May panic if the implementation of Ord for K does not implement a total order, or if
the Ord implementation or the key-function f panics.
All safe functions on slices preserve the invariant that even if the function panics, all
original elements will remain in the slice and any possible modifications via interior
mutability are observed in the input. This ensures that recovery code (for instance inside
of a Drop or following a catch_unwind) will still have access to all the original
elements. For instance, if the slice belongs to a Vec, the Vec::drop method will be able
to dispose of all contained elements.
§Examples
1.34.0 · Sourcepub fn sort_by_cached_key<K, F>(&mut self, f: F)
pub fn sort_by_cached_key<K, F>(&mut self, f: F)
Sorts the slice in ascending order with a key extraction function, preserving initial order of equal elements.
This sort is stable (i.e., does not reorder equal elements) and O(m * n + n * log(n)) worst-case, where the key function is O(m).
During sorting, the key function is called at most once per element, by using temporary storage to remember the results of key evaluation. The order of calls to the key function is unspecified and may change in future versions of the standard library.
If the implementation of Ord for K does not implement a total order, the function
may panic; even if the function exits normally, the resulting order of elements in the slice
is unspecified. See also the note on panicking below.
For simple key functions (e.g., functions that are property accesses or basic operations),
sort_by_key is likely to be faster.
§Current implementation
The current implementation is based on instruction-parallel-network sort by Lukas Bergdoll, which combines the fast average case of randomized quicksort with the fast worst case of heapsort, while achieving linear time on fully sorted and reversed inputs. And O(k * log(n)) where k is the number of distinct elements in the input. It leverages superscalar out-of-order execution capabilities commonly found in CPUs, to efficiently perform the operation.
In the worst case, the algorithm allocates temporary storage in a Vec<(K, usize)> the
length of the slice.
§Panics
May panic if the implementation of Ord for K does not implement a total order, or if
the Ord implementation panics.
All safe functions on slices preserve the invariant that even if the function panics, all
original elements will remain in the slice and any possible modifications via interior
mutability are observed in the input. This ensures that recovery code (for instance inside
of a Drop or following a catch_unwind) will still have access to all the original
elements. For instance, if the slice belongs to a Vec, the Vec::drop method will be able
to dispose of all contained elements.
§Examples
Sourcepub fn to_vec_in<A: Allocator>(&self, alloc: A) -> Vec<T, A>where
T: Clone,
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fn to_vec_in<A: Allocator>(&self, alloc: A) -> Vec<T, A>where
T: Clone,
allocator_api #32838)Copies self into a new Vec with an allocator.
§Examples
1.0.0 · Sourcepub fn concat<Item: ?Sized>(&self) -> <Self as Concat<Item>>::Outputwhere
Self: Concat<Item>,
pub fn concat<Item: ?Sized>(&self) -> <Self as Concat<Item>>::Outputwhere
Self: Concat<Item>,
Flattens a slice of T into a single value Self::Output.
§Examples
1.3.0 · Sourcepub fn join<Separator>(
&self,
sep: Separator,
) -> <Self as Join<Separator>>::Outputwhere
Self: Join<Separator>,
pub fn join<Separator>(
&self,
sep: Separator,
) -> <Self as Join<Separator>>::Outputwhere
Self: Join<Separator>,
Flattens a slice of T into a single value Self::Output, placing a
given separator between each.
§Examples
1.0.0 · Sourcepub fn connect<Separator>(
&self,
sep: Separator,
) -> <Self as Join<Separator>>::Outputwhere
Self: Join<Separator>,
👎Deprecated since 1.3.0: renamed to join
pub fn connect<Separator>(
&self,
sep: Separator,
) -> <Self as Join<Separator>>::Outputwhere
Self: Join<Separator>,
renamed to join
Flattens a slice of T into a single value Self::Output, placing a
given separator between each.
§Examples
1.23.0 · Sourcepub fn to_ascii_uppercase(&self) -> Vec<u8>
pub fn to_ascii_uppercase(&self) -> Vec<u8>
Returns a vector containing a copy of this slice where each byte is mapped to its ASCII upper case equivalent.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.
To uppercase the value in-place, use make_ascii_uppercase.
1.23.0 · Sourcepub fn to_ascii_lowercase(&self) -> Vec<u8>
pub fn to_ascii_lowercase(&self) -> Vec<u8>
Returns a vector containing a copy of this slice where each byte is mapped to its ASCII lower case equivalent.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.
To lowercase the value in-place, use make_ascii_lowercase.