From 0aaf9dca93c7a0edb1bdbadb9be373750466420d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 3 May 2021 13:25:55 +0100 Subject: [PATCH] utils: Provide and use ::rewind() Signed-off-by: Ian Jackson --- src/bin/otter.rs | 2 +- src/prelude.rs | 1 - src/spec.rs | 2 +- src/utils.rs | 6 ++++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index c757e1c4..1c663db7 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -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, diff --git a/src/prelude.rs b/src/prelude.rs index 70847be9..223f6c88 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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; diff --git a/src/spec.rs b/src/spec.rs index be423347..8b707c21 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -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.")?; diff --git a/src/utils.rs b/src/utils.rs index 3c2a20d8..204a3679 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -607,3 +607,9 @@ fn test_digest_write() { assert_eq!( got, exp ); assert_eq!( &obuffer, b"xyz\0" ); } + +#[ext(pub, name=SeekExt)] +impl T { + #[throws(io::Error)] + fn rewind(&mut self) { self.seek(io::SeekFrom::Start(0))? } +} -- 2.30.2