๐ฅ Rust Monads
(not an official identifier, used for simplification)
Types
Shared Functions
Note: monad
/ Monad
stands for Option or Result
Unwrap
monad.unwrap_or(fallback)
โ returns success value, fallback if it doesnโt existmonad.unwrap_or_else(fallback_fn)
โ returns success value, calls fallback fn / closure if it doesnโt existmonad.unwrap()
โ returns success value, panic if it doesnโt existmonad.expect(message)
โ like.unwrap()
, also printsmessage
Map
monad.map(self, f: F)
โ Maps aResult<T, E>
toResult<U, E>
by applying a function/closureop
to it, fail value untouchedmonad.map_err(self, op: F)
โ likemap()
, but for Emonad.map_or(self, default,f: F)
โ Maps aResult<T, E>
toResult<U, E>
by applying a function/closuref
to it, or returns default if E existsmonad.map_or_else(self, default, op: F)
โ lazy call ofmap_or
, use if passing function call as default
References
monad.as_ref()
โ Converts&Monad<T>
toMonad<&T>
monad.as_mut()
โ Converts&mut Monad<T>
toMonad<&mut T>