// settings: Result<String, io::Error> let settings = fs::read_to_string("~/settings.json"); // But why not a pair (String, io::Error)? let (settings, error) = fs::read_to_string("~/settings.json"); }
Result.new(error: "Ran out of pumpkins!") result. or_else { |e| ... }. and_then { |v| ... } # Is this possible? :/ What do we do here? Result.new( value: "Everything is great!", error: "Everything is broken!" )
individual_result.success? result.value << individual_result else result.error << "Something went wrong with #{individual_result}" end end # (Basic usage of `Result`, no `and_then`/`or_else`) # Temporary/intermediate step – a patch
{...} fn main() { let input = Article::new( "Hello!", "My email is [email protected]!" ); let pattern = Regex::new(r"\S+@\S+\.\S+").unwrap(); if input.search(&pattern) { println!("It's a match!"); } }
Article::new( "Hello!", r#" My email is [email protected]! I've got another one at [email protected]! "# ); let is_match: bool = input.search(&pattern); let actual_match: Option<String> = input.search(&pattern); let all_the_matches: Vec<String> = input.search(&pattern); }
Article::new( "Hello!", r#" My email is [email protected]! I've got another one at [email protected]! "# ); if input.search(&pattern) { println!("Yes, a match!"); } if let Some(m) = input.search(&pattern) { println!("Yes, a match: {}!", m); } }
Article::new( "Hello!", r#" My email is [email protected]! I've got another one at [email protected]! "# ); let all_the_matches: Vec<String> = input.search(&pattern); for m in all_the_matches { println!("One of the matches is: {}", m); } }
feature: The first one is about [...] error messages. [...] annoying situations where you had to try to figure out what was going on. The second one is to go back to some Rust fundamentals: being explicit. […] – The GTK-rs team