3 ms·
Can you elaborate on the usage of your error type? Is the implicit conversion via return type and ? operator sufficient? E.g., fn add(s1: &str, s2: &str) -
by loeg 3y ago
Can you elaborate on the usage of your error type? Is the implicit conversion via return type and ? operator sufficient? E.g.,
fn add(s1: &str, s2: &str) -> Result<i64, MyError> {
...
let i1 = i64::from_str_radix(s1, radix)?;
...
}
Thanks!
- Zezima 3y agoNot the poster. What exactly are you asking about? The usage of the error type the OP wrote is to get the line number of any error without using a macro on top of every single function in our crate. The person who wrote `MyError` accomplished it by defining their error type as "something that can be constructed from any other error" (`impl From<E: StdErr> for MyError`) and additionally heap-allocated the original error with `Box::new(error)`. So the usage would be to write one single error type in a crate which can "capture" or be constructed from any error type `E` and also prints out the line number of that error via `impl Display for MyError`.
- SpaceNugget 3y agoNot the person who posted the snippet. Yea, that should work. It tracks the position of the line that calls from() on the other error to convert it into MyError, which is what the ? operator will expand into.