Skip to content

Instantly share code, notes, and snippets.

@trvswgnr
Created March 25, 2025 17:05
Show Gist options
  • Save trvswgnr/ef438ba91299ec9294f0376e00cd9558 to your computer and use it in GitHub Desktop.
Save trvswgnr/ef438ba91299ec9294f0376e00cd9558 to your computer and use it in GitHub Desktop.
pipe in rust
#[derive(Debug)]
struct Pipe<T>(T);
impl<T> std::ops::Deref for Pipe<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T, F, U> std::ops::Shr<F> for Pipe<T>
where
F: FnOnce(T) -> U,
{
type Output = Pipe<U>;
fn shr(self, f: F) -> Self::Output {
Pipe(f(self.0))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment