且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取文件中的当前光标位置?

更新时间: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.