|
FWIW, for the process_item function, I've found writing it like: struct Item {
value: u32,
}
fn process_item(input: Option<Item>) -> Option<Item> {
input.map(|mut item| {
item.value += 3;
item
})
}
to be more "idiomatic" instead of doing the match on the Option. The methods like "unwrap_or...()", "map...()", "ok...()", "and_then()", etc. on Result/Option are very useful, if not a bit difficult to find the right one to use sometimes. Deeply nested match, "if let Some", etc. code becomes like a straight chain of method calls. In the end, I find that the Result/Option methods shorten code considerably and improve readability.Also, instead of doing an unwrap() on optional values for assertion, sometimes I like: let my_list = vec![1,2,3];
assert_eq!(Some(&my_list[0]), my_list.first());
Mostly just depends though since I don't care too much in tests. |