Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose AutoStream getters for the wrapped RawStream #222

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion crates/anstream/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,29 @@ where
}
}

/// Get the wrapped [`RawStream`]
/// Returns a reference to the wrapped [`RawStream`].
#[inline]
pub fn as_inner(&self) -> &S {
match &self.inner {
StreamInner::PassThrough(w) => w,
StreamInner::Strip(w) => w.as_inner(),
#[cfg(all(windows, feature = "wincon"))]
StreamInner::Wincon(w) => w.as_inner(),
}
}

/// Returns a mutable reference to the wrapped [`RawStream`].
#[inline]
pub fn as_inner_mut(&mut self) -> &mut S {
match &mut self.inner {
StreamInner::PassThrough(w) => w,
StreamInner::Strip(w) => w.as_inner_mut(),
#[cfg(all(windows, feature = "wincon"))]
StreamInner::Wincon(w) => w.as_inner_mut(),
}
}

/// Get the wrapped [`RawStream`].
#[inline]
pub fn into_inner(self) -> S {
match self.inner {
Expand Down
16 changes: 14 additions & 2 deletions crates/anstream/src/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<S> StripStream<S>
where
S: std::io::Write,
{
/// Only pass printable data to the inner `Write`
/// Only pass printable data to the inner `Write`.
#[inline]
pub fn new(raw: S) -> Self {
Self {
Expand All @@ -25,7 +25,19 @@ where
}
}

/// Get the wrapped [`std::io::Write`]
/// Returns a reference to the wrapped [`std::io::Write`].
#[inline]
pub fn as_inner(&self) -> &S {
&self.raw
}

/// Returns a mutable reference to the wrapped [`std::io::Write`].
#[inline]
pub fn as_inner_mut(&mut self) -> &mut S {
&mut self.raw
}

/// Get the wrapped [`std::io::Write`].
#[inline]
pub fn into_inner(self) -> S {
self.raw
Expand Down
14 changes: 12 additions & 2 deletions crates/anstream/src/wincon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<S> WinconStream<S>
where
S: anstyle_wincon::WinconStream,
{
/// Only pass printable data to the inner `Write`
/// Only pass printable data to the inner `Write`.
#[inline]
pub fn new(raw: S) -> Self {
Self {
Expand All @@ -29,7 +29,17 @@ where
}
}

/// Get the wrapped [`anstyle_wincon::WinconStream`]
/// Returns a reference to the wrapped [`anstyle_wincon::WinconStream`].
pub fn as_inner(&self) -> &S {
&self.raw
}

/// Returns a mutable reference to the wrapped [`anstyle_wincon::WinconStream`].
pub fn as_inner_mut(&mut self) -> &mut S {
&mut self.raw
}

/// Get the wrapped [`anstyle_wincon::WinconStream`].
#[inline]
pub fn into_inner(self) -> S {
self.raw
Expand Down