Created
March 25, 2025 17:05
-
-
Save trvswgnr/ef438ba91299ec9294f0376e00cd9558 to your computer and use it in GitHub Desktop.
pipe in rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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