TIL: Rust Option Methods
Today I learned about some lesser-known Option methods in Rust that can make code cleaner:
Option::inspect()- Run a closure on the value ifSome, useful for loggingOption::filter()- ConvertSome(x)toNoneif predicate returns falseOption::zip()- Combine two Options intoOption<(A, B)>
let x = Some(5);x.inspect(|v| println!("Value: {v}")) .filter(|v| *v > 3) .zip(Some("hello"))These are great for building pipelines without early returns!