chiark / gitweb /
utils: Provide and use <T as Seek>::rewind()
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 12:25:55 +0000 (13:25 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 12:25:55 +0000 (13:25 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/prelude.rs
src/spec.rs
src/utils.rs

index c757e1c4f177706b28408987691d69bca330fe76..1c663db7abe520964aecab9791c9c5d4a4efd98d 100644 (file)
@@ -1347,7 +1347,7 @@ mod upload_bundle {
       dw.finish().0
     };
     let kind = bundles::Kind::only();
-    f.seek(io::SeekFrom::Start(0)).context("rewind bundle file")?;
+    f.rewind().context("rewind bundle file")?;
     let cmd = MC::UploadBundle {
       game: instance_name.clone(),
       hash: bundles::Hash(hash.into()), kind,
index 70847be91353c0269301ea0fa81673c096185c66..223f6c88e1214c7210ba11ecb14ba6a9a488643c 100644 (file)
@@ -29,7 +29,6 @@ pub use std::hash::Hash;
 pub use std::io;
 pub use std::io::ErrorKind;
 pub use std::io::{BufRead, BufReader, BufWriter, Read, Write};
-pub use std::io::{Seek, SeekFrom};
 pub use std::iter;
 pub use std::iter::repeat_with;
 pub use std::marker::PhantomData;
index be4233478263425ae3e7adbae2cb845d3b288396..8b707c2134b8581a6de6ad36d190f6c9e03b0675 100644 (file)
@@ -540,7 +540,7 @@ pub mod imp {
         let mut messagefile = tempfile::tempfile().context("tempfile")?;
         messagefile.write_all(message.as_bytes()).context("write")?;
         messagefile.flush().context("flush")?;
-        messagefile.seek(SeekFrom::Start(0)).context("seek")?;
+        messagefile.rewind().context("seek")?;
         Ok::<_,AE>(messagefile)
       })().context("write email to temporary file.")?;
 
index 3c2a20d846f54edd157e7040c9dcbcc093dcced7..204a3679e2f4653147b06511387e4fb58095d4fc 100644 (file)
@@ -607,3 +607,9 @@ fn test_digest_write() {
   assert_eq!( got, exp );
   assert_eq!( &obuffer, b"xyz\0" );
 }
+
+#[ext(pub, name=SeekExt)]
+impl<T: io::Seek> T {
+  #[throws(io::Error)]
+  fn rewind(&mut self) { self.seek(io::SeekFrom::Start(0))? }
+}