How to handle errors inside a closure that retruns ()
⚓ Rust 📅 2026-03-09 👤 surdeus 👁️ 1The key problem is how to handle error inside a closure that retruns ().
#[allow(clippy::unwrap_used)]
pub fn backup_newest_in<V: AsRef<[DirEntry]>>(v: V) -> anyhow::Result<()> {
let mut v = v.as_ref().to_owned();
if v.is_empty() {
return Err(anyhow::anyhow!("nothing to backup"));
}
//here
v.sort_by_key(|d: &DirEntry| d.metadata().unwrap().modified().unwrap());
todo!()
}
can we handle this without unwrap()?
2 posts - 2 participants
🏷️ Rust_feed