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

Write a value to an element of this slice.

Panics

Panics if idx is out of bounds.

Trait Implementations

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.