Struct positioned_io::Slice [] [src]

pub struct Slice<I> { /* fields omitted */ }

A window into another ReatAt or WriteAt.

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


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.as_ref(), 4, Some(4));

let mut buf = [0; 4];
let bytes = try!(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);
    try!(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]);


impl<I> Slice<I>

Create a new Slice.

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

impl<I> Slice<I> where
    I: Size

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

impl<I> ReadAt for Slice<I> where
    I: ReadAt

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

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

impl<I> WriteAt for Slice<I> where
    I: WriteAt

Write a buffer at an offset, returning the number of bytes written. Read more

Flush this writer, ensuring that any buffered data is written. Read more

Write a complete buffer at an offset. Read more

impl<I> Size for Slice<I>

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