std::io::Seek

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

Files implement Seek:

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

let mut f = File::open("foo.txt")?;

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

Required Methods

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

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

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.

Implementors

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/io/trait.Seek.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部