Struct write_ref::WriteSlice
source · pub struct WriteSlice<'a, T: 'a>(_);
Expand description
Represents a write-only buffer.
You only write to individual elements of this slice; you can’t modify the slice itself or read from its elements.
It is generally advised to take an impl Into<WriteSlice>
instead of a
WriteSlice
itself in APIs so that callers can pass in a a mutable
reference.
Examples
fn copy<'a, T: Clone + 'a>(input: &[T], output: impl Into<WriteSlice<'a, T>>) {
let mut output = output.into();
for (i, val) in input.iter().enumerate() {
output.write(i, val.clone());
}
}
fn main() {
let input = [1, 2, 3];
let mut output = [7, 1, 9];
copy(&input, &mut output as &mut [_]);
assert_eq!(input, output);
}
Implementations
Trait Implementations
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for WriteSlice<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for WriteSlice<'a, T>where
T: Send,
impl<'a, T> Sync for WriteSlice<'a, T>where
T: Sync,
impl<'a, T> Unpin for WriteSlice<'a, T>
impl<'a, T> !UnwindSafe for WriteSlice<'a, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more