Skip to content

Commit 9bdac31

Browse files
author
Andrea Calabrese
committed
Remove Seek from required traits
We read linearly, so we do not need to seek within a file Signed-off-by: Andrea Calabrese <andrea.calabrese@amarulasolutions.com>
1 parent aeadaab commit 9bdac31

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/uu/base32/src/base_common.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use clap::{Arg, ArgAction, Command};
99
use std::ffi::OsString;
1010
use std::fs::File;
11-
use std::io::{self, ErrorKind, Read, Seek};
11+
use std::io::{self, ErrorKind, Read};
1212
use std::path::{Path, PathBuf};
1313
use uucore::display::Quotable;
1414
use uucore::encoding::{
@@ -149,29 +149,19 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
149149
)
150150
}
151151

152-
/// A trait alias for types that implement both `Read` and `Seek`.
153-
pub trait ReadSeek: Read + Seek {}
154-
155-
/// Automatically implement the `ReadSeek` trait for any type that implements both `Read` and `Seek`.
156-
impl<T: Read + Seek> ReadSeek for T {}
157-
158-
pub fn get_input(config: &Config) -> UResult<Box<dyn ReadSeek>> {
152+
pub fn get_input(config: &Config) -> UResult<Box<dyn Read>> {
159153
match &config.to_read {
160154
Some(path_buf) => {
161155
// Do not buffer input, because buffering is handled by `fast_decode` and `fast_encode`
162156
let file =
163157
File::open(path_buf).map_err_context(|| path_buf.maybe_quote().to_string())?;
164158
Ok(Box::new(file))
165159
}
166-
None => {
167-
let mut buffer = Vec::new();
168-
io::stdin().read_to_end(&mut buffer)?;
169-
Ok(Box::new(io::Cursor::new(buffer)))
170-
}
160+
None => Ok(Box::new(io::stdin())),
171161
}
172162
}
173163

174-
pub fn handle_input<R: Read + Seek>(input: &mut R, format: Format, config: Config) -> UResult<()> {
164+
pub fn handle_input<R: Read>(input: &mut R, format: Format, config: Config) -> UResult<()> {
175165
let supports_fast_decode_and_encode = get_supports_fast_decode_and_encode(format);
176166

177167
let supports_fast_decode_and_encode_ref = supports_fast_decode_and_encode.as_ref();

0 commit comments

Comments
 (0)