3 ms·
FWIW > Result which is a plain old datatype written in the language, though admittedly it relies on a macro for use It does not. It relies on a special constr
by masklinn 9y ago
FWIW
> Result which is a plain old datatype written in the language, though admittedly it relies on a macro for use
It does not. It relies on a special construct (!) or macro (try!) for convenience, but these are not necessary (a popular alternative is to use the various HoFs instead) and desugar to pretty trivial (if possibly repetitive) code:
macro_rules! try {
($expr:expr) => (match $expr {
$crate::result::Result::Ok(val) => val,
$crate::result::Result::Err(err) => {
return $crate::result::Result::Err($crate::convert::From::from(err))
}
})
}
- steveklabnik 9y ago(It's ? not !)
- masklinn 9y ago(You're right of course, not sure what I was thinking)
- lmm 9y agoI don't think Result would be seen as an acceptable replacement for exceptions without the macro/special construct. But I should've been clearer.