Trait Seek

Source
pub trait Seek {
    // Required method
    fn poll_seek(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        pos: SeekFrom,
    ) -> Poll<Result<u64>>;

    // Provided method
    fn seek(&mut self, pos: SeekFrom) -> ImplFuture<Result<u64>>
       where Self: Unpin { ... }
}
Expand description

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§

Source

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.

Provided Methods§

Source

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?;

Implementations on Foreign Types§

Source§

impl<T: Seek + Unpin + ?Sized> Seek for &mut T

Source§

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

Source§

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

Source§

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

Implementors§

Source§

impl Seek for &File

Source§

impl Seek for File

Source§

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

Source§

impl<R: Seek> Seek for BufReader<R>

Source§

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

Source§

impl<W: Write + Seek> Seek for BufWriter<W>