#[derive(Debug, Snafu)]
pub enum Myerror{
NameNotFound{name:String},
/*
and so on - other errors are here
*/
}
//this function searches for a name in database.
//if the 'name' is found, return Ok(). else return respective Err() .
//and if 'name' is invalid then return trait object like below.
fn search_name(name:&str) -> Result<String,Box<dyn Error + Send + Sync>> {
/*
ignore the code here.
*/
//one of the error case is - if the 'name' is not matched return a trait object like below
return Err(Box::new(Myerror::NameNotFound{name:name.to_string()}));
}
//main code
fn main() {
if let Err(err) = search_name("user"){
//Here if 'name' is not matched just wait don't exit from main().
//But i have issue here while comparing trait object returned from search_name with "Myerror::NameNotFound"
if err == Myerror::NameNotFound{ //line no 24
//
println!("name {} not found",name);
// wait()
}
//for every other error, exit from main
else{
return ;
}
}
//ok case - continue
else {
//continue with execution
}
}
At line no 24
I need to check whether error returned from search_name
is NameNotFound
or not. How to do this? .