Skip to content

Commit

Permalink
feat: Expose AutoStream getters for the wrapped RawStream
Browse files Browse the repository at this point in the history
`AutoStream` can be consumed to get the wrapped `S: RawStream`, but there
is currently no way to get a reference to it.
  • Loading branch information
DaniPopes committed Oct 24, 2024
1 parent 5066a91 commit 900d738
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
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.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.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

0 comments on commit 900d738

Please sign in to comment.