[][src]Trait sgx_tstd::io::Seek

pub trait Seek {
    fn seek(&mut self, pos: SeekFrom) -> Result<u64>;

    fn stream_len(&mut self) -> Result<u64> { ... }
fn stream_position(&mut self) -> Result<u64> { ... } }

The Seek trait provides a cursor which can be moved within a stream of bytes.

The stream typically has a fixed size, allowing seeking relative to either end or the current offset.

Required methods

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

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

A seek beyond the end of a stream is allowed, but behavior is defined by the implementation.

If the seek operation completed successfully, this method returns the new position from the start of the stream. That position can be used later with SeekFrom::Start.


Seeking to a negative offset is considered an error.

Loading content...

Provided methods

fn stream_len(&mut self) -> Result<u64>

Returns the length of this stream (in bytes).

This method is implemented using up to three seek operations. If this method returns successfully, the seek position is unchanged (i.e. the position before calling this method is the same as afterwards). However, if this method returns an error, the seek position is unspecified.

If you need to obtain the length of many streams and you don't care about the seek position afterwards, you can reduce the number of seek operations by simply calling seek(SeekFrom::End(0)) and using its return value (it is also the stream length).

Note that length of a stream can change over time (for example, when data is appended to a file). So calling this method multiple times does not necessarily return the same length each time.

fn stream_position(&mut self) -> Result<u64>

Returns the current seek position from the start of the stream.

This is equivalent to self.seek(SeekFrom::Current(0)).

Loading content...


impl Seek for SgxFile[src]

impl Seek for File[src]

impl<'_> Seek for &'_ File[src]

impl<'a> Seek for &'a SgxFile[src]

impl<R: Seek> Seek for BufReader<R>[src]

fn seek(&mut self, pos: SeekFrom) -> Result<u64>[src]

Seek to an offset, in bytes, in the underlying reader.

The position used for seeking with SeekFrom::Current(_) is the position the underlying reader would be at if the BufReader<R> had no internal buffer.

Seeking always discards the internal buffer, even if the seek position would otherwise fall within it. This guarantees that calling .into_inner() immediately after a seek yields the underlying reader at the same position.

To seek without discarding the internal buffer, use BufReader::seek_relative.

See std::io::Seek for more details.

Note: In the edge case where you're seeking with SeekFrom::Current(n) where n minus the internal buffer length overflows an i64, two seeks will be performed instead of one. If the second seek returns Err, the underlying reader will be left at the same position it would have if you called seek with SeekFrom::Current(0).

impl<S: Seek + ?Sized> Seek for Box<S>[src]

impl<S: Seek + ?Sized, '_> Seek for &'_ mut S[src]

impl<T> Seek for Cursor<T> where
    T: AsRef<[u8]>, 

impl<W: Write + Seek> Seek for BufWriter<W>[src]

fn seek(&mut self, pos: SeekFrom) -> Result<u64>[src]

Seek to the offset, in bytes, in the underlying writer.

Seeking always writes out the internal buffer before seeking.

Loading content...