Compare commits

...

5 Commits

Author SHA1 Message Date
Stephan Rehfeld
019fbcf095 use unwrap_or to get default value 2026-04-08 18:46:40 +02:00
Stephan Rehfeld
20c675ef91 You can use unwrap to get value. Panics, if result is Err 2026-04-08 18:43:12 +02:00
Stephan Rehfeld
6e0e031b12 Optional and Result for optional parameters and functions that may fail. 2026-04-08 18:41:31 +02:00
Stephan Rehfeld
d5427c96ca Enum values can contain futher values. Use pattern matching to access. 2026-04-08 18:19:44 +02:00
Stephan Rehfeld
092e5693b7 Simple enum with match 2026-04-08 18:16:15 +02:00

View File

@ -1,5 +1,14 @@
fn main() { fn add_10(value: Option<u32>) -> Result<u32, String> {
for value in (-10..10).rev() { match value {
println!("Value: {}", value); Some(v) => Ok(v + 10),
None => Err(String::from("value was empty")),
} }
} }
fn main() {
let value = add_10(None);
println!("Result is: {}", value.unwrap_or(42));
panic!("Non recoverable error.");
}