Rust docs show a std::io::Error being created using
let custom_error = Error::new(ErrorKind::Other, "oh no!");
and new has a type signature of
fn new<E>(kind: ErrorKind, error: E) -> Error
where E: Into<Box<std::error::Error + Send + Sync>>
I've found an implementation of impl<T: std::error::Error> std::error::Error for Box<T> but cannot find one for &'static str like the one used in the example.
What trait is used to achieve Into<Error> for strings?
Given:
impl<'a> From<&'a str> for Box<Error> (see the From docs)impl<T, U> Into<U> for T where U: From<T> (see the Into docs)Substitute T = &'a str and U = Box<Error>, which gives you:
impl<'a> Into<Box<Error>> for &'a strIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With