wc: split WordCountable trait to exclude inner_file on wasi

This commit is contained in:
Sylvestre Ledru
2026-04-03 12:15:40 +02:00
parent 409eb11d75
commit 65596fe0ac
+27 -1
View File
@@ -20,13 +20,20 @@ pub trait WordCountable: AsFd + AsRawFd + Read {
fn inner_file(&mut self) -> Option<&mut File>;
}
#[cfg(not(unix))]
#[cfg(all(not(unix), not(target_os = "wasi")))]
pub trait WordCountable: Read {
type Buffered: BufRead;
fn buffered(self) -> Self::Buffered;
fn inner_file(&mut self) -> Option<&mut File>;
}
#[cfg(target_os = "wasi")]
pub trait WordCountable: Read {
type Buffered: BufRead;
fn buffered(self) -> Self::Buffered;
}
#[cfg(not(target_os = "wasi"))]
impl WordCountable for StdinLock<'_> {
type Buffered = Self;
@@ -38,6 +45,16 @@ impl WordCountable for StdinLock<'_> {
}
}
#[cfg(target_os = "wasi")]
impl WordCountable for StdinLock<'_> {
type Buffered = Self;
fn buffered(self) -> Self::Buffered {
self
}
}
#[cfg(not(target_os = "wasi"))]
impl WordCountable for File {
type Buffered = BufReader<Self>;
@@ -49,3 +66,12 @@ impl WordCountable for File {
Some(self)
}
}
#[cfg(target_os = "wasi")]
impl WordCountable for File {
type Buffered = BufReader<Self>;
fn buffered(self) -> Self::Buffered {
BufReader::new(self)
}
}