[][src]Trait async_std::io::Seek

pub trait Seek {
    fn poll_seek(
        self: Pin<&mut Self>,
        cx: &mut Context,
        pos: SeekFrom
    ) -> Poll<Result<u64>>; fn seek(&mut self, pos: SeekFrom) -> ImplFuture<Result<u64>>
    where
        Self: Unpin
, { ... } }

Allows seeking through a byte stream.

This trait is a re-export of futures::io::AsyncSeek and is an async version of std::io::Seek.

The provided methods do not really exist in the trait itself, but they become available when SeekExt the prelude is imported:

use async_std::prelude::*;

Required methods

fn poll_seek(
    self: Pin<&mut Self>,
    cx: &mut Context,
    pos: SeekFrom
) -> Poll<Result<u64>>

Attempt to seek to an offset, in bytes, in a stream.

Loading content...

Provided methods

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

Seeks to a new position in a byte stream.

Returns the new position in the byte stream.

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

Examples

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

let mut file = File::open("a.txt").await?;

let file_len = file.seek(SeekFrom::End(0)).await?;
Loading content...

Implementations on Foreign Types

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

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

Loading content...

Implementors

impl Seek for File[src]

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

impl<P> Seek for Pin<P> where
    P: DerefMut + Unpin,
    <P as Deref>::Target: Seek
[src]

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

fn poll_seek(
    self: Pin<&mut Self>,
    cx: &mut Context,
    pos: SeekFrom
) -> Poll<Result<u64>>
[src]

Seeks 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.

See 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<T> Seek for Cursor<T> where
    T: AsRef<[u8]> + Unpin
[src]

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

fn poll_seek(
    self: Pin<&mut Self>,
    cx: &mut Context,
    pos: SeekFrom
) -> Poll<Result<u64>>
[src]

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

Seeking always writes out the internal buffer before seeking.

Loading content...