Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. use std::io;
  2. use std::io::prelude::*;
  3. use std::io::{Cursor, SeekFrom};
  4.  
  5. trait Tell {
  6. fn tell(&mut self) -> io::Result<u64>;
  7. }
  8.  
  9. impl<T: Seek> Tell for T {
  10. fn tell(&mut self) -> io::Result<u64> {
  11. self.seek(SeekFrom::Current(0))
  12. }
  13. }
  14.  
  15. fn main() -> io::Result<()> {
  16. let mut f = Cursor::new(vec![0; 15]);
  17.  
  18. // move the cursor 5 bytes from the start of the file
  19. f.seek(SeekFrom::Start(5))?;
  20.  
  21. println!("{:?}", f.tell());
  22.  
  23. Ok(())
  24. }
Add Comment
Please, Sign In to add comment