by loeg · 3y ago · 0 comments
fn add(s1: &str, s2: &str) -> Result<i64, MyError> {
...
let i1 = i64::from_str_radix(s1, radix)?;
...
}
Thanks!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`.