tap
tap copied to clipboard
Generic extensions for tapping values in Rust.
Often when dealing with locks or something I tend to just do `lock.tap_mut(...)` which gets a `&mut self` however this triggers must use warnings. Alternatively i use `pipe` to solve...
I found that it didn't make much sense to have conditional versions of each by-ref `pipe` method, so I did that for `tap` instead. Closes #7.
Reading [this comment](https://users.rust-lang.org/t/builder-pattern-in-rust-self-vs-mut-self-and-method-vs-associated-function/72892/2) on the rust internals forum got me interested in a conditional pipe method; to borrow the example from the post, it would simplify pipes with basic tests...
Add something like ```rust trait TapResult: Tap { fn tap_result(self, f: impl FnOnce(&Self) -> std::result::Result) -> std::result::Result { f(&self).map(|()| self) } fn tap_result_mut(mut self, f: impl FnOnce(&mut Self) -> std::result::Result)...
`.as_ref(t)` is too verbose, and breaks reading right-to-left. I figured this calls for a helper trait for `AsRef` and `AsMut` invocations. Type inference is pretty good for spots that need...
Currently, `pipe_deref` is defined like so: ```rs fn pipe_deref(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where Self: Deref, Self::Target: 'a, R: 'a + Sized, { ... }...
I code this: ``` rust use std::io::stdin; String::new().tap_mut(|s| stdin().read_line(s).unwrap()) ``` Getting error message: ``` none xx | String::new().tap_mut(|s| stdin().read_line(s).unwrap()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize` ``` It can be solved...
DO NOT MERGE This is a test PR to trial using the new try_trait_v2 feature with TapFallible inspired by the note[^1] in the TapOptional docs indicating that it was slated...
See also: #5