更新时间:2023-01-27 15:32:15
You should call Seek:seek
with a relative offset of 0. This has no side effect and returns the information you are looking for.
Seek
用于多种类型,包括:
Seek
is implemented for a number of types, including:
impl Seek for File
impl<'_> Seek for &'_ File
impl<'_, S: Seek + ?Sized> Seek for &'_ mut S
impl<R: Seek> Seek for BufReader<R>
impl<S: Seek + ?Sized> Seek for Box<S>
impl<T> Seek for Cursor<T> where
impl<W: Write + Seek> Seek for BufWriter<W>
impl Seek for File
impl<'_> Seek for &'_ File
impl<'_, S: Seek + ?Sized> Seek for &'_ mut S
impl<R: Seek> Seek for BufReader<R>
impl<S: Seek + ?Sized> Seek for Box<S>
impl<T> Seek for Cursor<T> where
impl<W: Write + Seek> Seek for BufWriter<W>
使用 Cursor
类 可能会更有效,因为您可以避免进行额外的系统调用.
Using the Cursor
class mentioned by Aaronepower might be more efficient though, since you could avoid having to make an extra system call.