Struct positioned_io::Cursor [] [src]

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

Adapts a ReadAt or WriteAt into a Read or Write.

This wraps anything that read and write at offsets, turning into an object that can read or write at a file position. This allows you to use those types with all the many functions that expect a Read or Write.

Note that seeking on Cursor has limited functionality. We don't know how many bytes are available, so we can't use SeekFrom::End. See SizeCursor for another option.

Examples

use positioned_io::{ReadAt, Cursor};

struct NetworkStorage {
    // A remote disk that supports random access.
}
impl ReadAt for NetworkStorage {
    // ...
}

// Adapt our storage into a Read.
let storage = NetworkStorage::new(SOME_LOCATION);
let curs = Cursor::new_pos(storage, 1 << 30);

// Copy a segment to a file.
let mut input = curs.take(1 << 20);
let mut output = try!(File::create("segment.out"));
try!(io::copy(&mut input, &mut output));

Methods

impl<I> Cursor<I>
[src]

Create a new Cursor which starts reading at a specified offset.

Pass in a ReadAt or WriteAt as io.

Create a new Cursor which starts reading at offset zero.

Pass in a ReadAt or WriteAt as io.

Consume self and yield the inner ReadAt or WriteAt.

Borrow the inner ReadAt or WriteAt.

Borrow the inner ReadAt or WriteAt mutably.

Get the current read/write position.

Set the current read/write position.

Trait Implementations

impl<I> Seek for Cursor<I>
[src]

Seek to an offset, in bytes, in a stream. Read more

impl<I> Read for Cursor<I> where
    I: ReadAt
[src]

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read the exact number of bytes required to fill buf. Read more

Creates a "by reference" adaptor for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

🔬 This is a nightly-only experimental API. (io)

the semantics of a partial read/write of where errors happen is currently unclear and may change

Transforms this Read instance to an Iterator over chars. Read more

Creates an adaptor which will chain this stream with another. Read more

Creates an adaptor which will read at most limit bytes from it. Read more

impl<I> Write for Cursor<I> where
    I: WriteAt
[src]

Write a buffer into this object, returning how many bytes were written. Read more

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

Attempts to write an entire buffer into this write. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Creates a "by reference" adaptor for this instance of Write. Read more