satex_core/util/with.rs
1pub trait With: Sized {
2 fn with<F>(mut self, f: F) -> Self
3 where
4 F: FnOnce(&mut Self),
5 {
6 f(&mut self);
7 self
8 }
9
10 fn try_with<F, E>(mut self, f: F) -> Result<Self, E>
11 where
12 F: FnOnce(&mut Self) -> Result<(), E>,
13 {
14 match f(&mut self) {
15 Ok(_) => Ok(self),
16 Err(e) => Err(e),
17 }
18 }
19}
20
21impl<T: Sized> With for T {}