I do not know the convert path from my custom error to Box, can you show me the code?
This is the code (I do not want to use err.into(), because I hope to know how rust think about it)
Thank you!
use std::fmt;
use std::error::Error;
#[derive(Debug)]
pub enum CustomError {
A
}
impl fmt::Display for CustomError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "CustomError")
}
}
impl Error for CustomError {
}
fn return_error() -> Result<(),CustomError>{
return Err(CustomError::A);
}
fn test() -> Result<(),Box<dyn Error>> {
// it shows: expected trait object `dyn std::error::Error`, found enum `CustomError`
return_error().map_err(|err|Box::new(err))
}
fn main() {
test();
println!("Hello, world!");
}
Thank you!