1pub trait With: Sized {
3 fn wrap_with<U, F: FnOnce(Self) -> U>(self, f: F) -> U {
7 f(self)
8 }
9
10 #[must_use]
12 fn with<F: FnOnce(&mut Self)>(mut self, f: F) -> Self {
13 f(&mut self);
14 self
15 }
16
17 fn try_with<E, F>(mut self, f: F) -> Result<Self, E>
19 where
20 F: FnOnce(&mut Self) -> Result<(), E>,
21 {
22 f(&mut self)?;
23 Ok(self)
24 }
25
26 #[must_use]
28 fn with_if<F>(mut self, condition: bool, f: F) -> Self
29 where
30 F: FnOnce(&mut Self),
31 {
32 if condition {
33 f(&mut self);
34 }
35 self
36 }
37}
38
39impl<T: Sized> With for T {}