# 1.0.0[−][src]Trait std::io::Seek

    pub trait Seek {
        fn seek(&mut self, pos: SeekFrom) -> 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.

# Examples

`File`s implement `Seek`:

    use std::io;
    use std::io::prelude::*;
    use std::fs::File;
    use std::io::SeekFrom;

    fn main() -> io::Result<()> {
        let mut f = File::open("foo.txt")?;

        // move the cursor 42 bytes from the start of the file
        f.seek(SeekFrom::Start(42))?;
        Ok(())
    }Run

## 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`.

# Errors

Seeking to a negative offset is considered an error.

Loading content...

## Implementors

### `impl Seek for File`[src]

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

### `impl<'a> Seek for &'a File`[src]

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

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

#### `fn seek(&mut self, pos: SeekFrom) -> Result<u64>`[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` 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]

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

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

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

### `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...

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)