I made a crate called `evil`, which lets you use the `?` operator as a shorthand for `.unwrap()`
⚓ Rust 📅 2026-03-04 👤 surdeus 👁️ 3This crate lets you write this, with each ? equivalent to an .unwrap():
#[test]
fn user_theme_preference() -> evil::Result<()> {
let response = make_api_call("/user/profile/settings")?;
let json: Value = serde_json::from_str(&response)?;
let theme = json
.get("data")?
.get("attributes")?
.get("preferences")?
.get("theme")?
.as_str()?;
assert_eq!(theme, "dark");
evil::Ok(())
}
Instead of this:
#[test]
fn user_theme_preference() {
let response = make_api_call("/user/profile/settings").unwrap();
let json: Value = serde_json::from_str(&response).unwrap();
let theme = json
.get("data")
.unwrap()
.get("attributes")
.unwrap()
.get("preferences")
.unwrap()
.get("theme")
.unwrap()
.as_str()
.unwrap();
assert_eq!(theme, "dark");
}
GitHub:
3 posts - 2 participants
🏷️ Rust_feed