3 ms·
If do_something(), get_this(), get_that() and as_paper_airplane() all returned a Result then you could write your code as follows: my_struct.do_something()?
by davidhyde 6y ago
If do_something(), get_this(), get_that() and as_paper_airplane() all returned a Result then you could write your code as follows:
my_struct.do_something()?
.get_this()?
.get_that()?
.as_ref()
.as_paper_airplane()?;
If the error type of the result differs you can use map_err or write a converter by implementing the From trait for your the custom error struct you want to map to. The one thing you can't find out is if the calling function will panic in its function or a function that it calls. When you write embedded libraries you are never supposed to panic but there is nothing to enforce this which is, admittedly, not ideal.