pub struct Slice<I> { /* private fields */ }
Expand description

A window into another ReadAt or WriteAt.

Given an existing positioned I/O, this presents a limited view of it.

Examples

Some slices have size restrictions:

use positioned_io::{ReadAt, Slice};

let a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let slice = Slice::new(&a[..], 4, Some(4));

let mut buf = [0; 4];
let bytes = slice.read_at(2, &mut buf)?;
assert_eq!(bytes, 2);
assert_eq!(buf, [6, 7, 0, 0]);

Some slices do not:

use positioned_io::{WriteAt, Slice};

let mut v = vec![0, 1, 2, 3, 4, 5];
let buf = [9; 3];

{
    let mut slice = Slice::new(&mut v, 2, None);
    slice.write_all_at(3, &buf)?;
}

// The write goes right past the end.
assert_eq!(v, vec![0, 1, 2, 3, 4, 9, 9, 9]);

Implementations

Create a new Slice.

The slice will be a view of size bytes, starting at offset in io. If you do not pass a size, the size won’t be limited.

Create a new Slice that goes to the end of io.

Note that you can create a larger slice by passing a larger size to new(), but it won’t do you any good for reading.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Reads bytes from an offset in this source into a buffer, returning how many bytes were read. Read more

Reads the exact number of bytes required to fill buf from an offset. Read more

Get the size of this object, in bytes. Read more

Writes bytes from a buffer to an offset, returning the number of bytes written. Read more

Flush this writer, ensuring that any intermediately buffered data reaches its destination. Read more

Writes a complete buffer at an offset. Read more

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

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.