Skip to content

Commit 2a8ce67

Browse files
authored
od, uucore: Allow reusing RawReader (#12385)
1 parent 4da1068 commit 2a8ce67

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/uu/od/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ byteorder = { workspace = true }
2222
clap = { workspace = true }
2323
half = { workspace = true }
2424
rustix = { workspace = true, features = ["stdio"] }
25-
uucore = { workspace = true, features = ["parser-size"] }
25+
uucore = { workspace = true, features = ["fs", "parser-size"] }
2626
fluent = { workspace = true }
2727
libc.workspace = true
2828

src/uu/od/src/multifile_reader.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,7 @@ impl MultifileReader<'_> {
5656
// limit.
5757
#[cfg(any(unix, target_os = "wasi"))]
5858
{
59-
use std::os::fd::AsFd;
60-
// todo: definition is generic enough to move to uucore::io::RawReader if useful
61-
struct RawReader<T: AsFd>(pub T);
62-
impl<T: AsFd> io::Read for RawReader<T> {
63-
fn read(&mut self, b: &mut [u8]) -> io::Result<usize> {
64-
rustix::io::read(&self.0, b).map_err(Into::into)
65-
}
66-
}
67-
let stdin = RawReader(rustix::stdio::stdin());
59+
let stdin = uucore::io::RawReader(rustix::stdio::stdin());
6860
self.curr_file = Some(Box::new(stdin));
6961
}
7062

src/uucore/src/lib/mods/io.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ type NativeType = OwnedHandle;
3030
#[cfg(not(windows))]
3131
type NativeType = OwnedFd;
3232

33+
// create reader without buffering
34+
#[cfg(any(unix, target_os = "wasi"))]
35+
pub struct RawReader<T: AsFd>(pub T);
36+
#[cfg(any(unix, target_os = "wasi"))]
37+
impl<T: AsFd> io::Read for RawReader<T> {
38+
fn read(&mut self, b: &mut [u8]) -> io::Result<usize> {
39+
rustix::io::read(&self.0, b).map_err(Into::into)
40+
}
41+
}
42+
3343
// create writer without buffering
3444
#[cfg(any(unix, target_os = "wasi"))]
3545
pub struct RawWriter<T: AsFd>(pub T);

0 commit comments

Comments
 (0)