X XFediYour place in the Fediverse
XFEDI

Conversation

ActivityPub

Rust's `?` operator: a one-character try/except. 😍

let n: u32 = s.trim().parse()?;

If this returns Err, propagate it to the caller. Otherwise, give me the value.

What I like about this over Python exceptions is that Rust makes the possibility of failure explicit in the function signature:

Result<u32, E>

Media attachment
↩ Reply ♡ 0 · ↻ 0 ↗ Original

Oct 20, 2026 · 13:38 UTC

Replies