How to handle Error?
⚓ Rust 📅 2026-03-08 👤 surdeus 👁️ 2I want to don't use unwrap() in my code,but suddenly it become so wired especially in a clousure.In a closure I cannot handle error easyly by use ? because of the closure returns () not anyhow::Result<()> . Is there any resouce about error handle patten?
v.retain(|d| {
let e = d.path().extension();
if e.is_none() {
return false;
}
//[INFO] checked
let s = e.unwrap();
let s = s.to_str();
if s.is_none() {
return false;
}
let s = s.unwrap();
if s == "gz" {
return true;
}
false
});
another question is that is there anyway to handle error without return to upper function that better than match or if let Err(e) = run().
2 posts - 2 participants
🏷️ Rust_feed