Created
January 8, 2026 21:01
-
-
Save orzklv/fa3ad6f64cc9028afeca81685478daf9 to your computer and use it in GitHub Desktop.
Preserve self instance while applying a closure function.
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
| /// Apply closure function preserving self instance | |
| pub trait TryTap: Sized { | |
| fn try_tap<E>(self, f: impl FnOnce(&Self) -> Result<(), E>) -> Result<Self, E>; | |
| } | |
| impl<T> TryTap for T { | |
| fn try_tap<E>(self, f: impl FnOnce(&Self) -> Result<(), E>) -> Result<Self, E> { | |
| f(&self)?; | |
| Ok(self) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment