I'm kinda new to Rust and there are lots of match patterns, which I find great. The problem is that it tends to get nested if I want to do lots of things that need match patterning:
let codec = ffmpeg_next::codec::find_by_name("h264");
match codec {
Ok(codec) => {
//... more nested matches
},
Err(e) => {
}
}
I could simply unwrap() like this:
let codec = ffmpeg_next::codec::find_by_name("h264");
coded.unwrap().do_something();
however I don want panics, I want to handle errors if something happens.
How can I unwrap OR deal with the error.
I found https://doc.rust-lang.org/beta/std/option/enum.Option.html#method.contains but its experimental:
let codec = ffmpeg_next::codec::find_by_name("h264");
if !codec.contains() {
//deal with error and return
}
I could use match for it:
let codec = ffmpeg_next::codec::find_by_name("h264");
match codec {
Ok(codec) => {
// do nothing
},
Err(e) => {
//deal with error and return
}
}
//continue using codec here
but I think I'm cheating Rust's error handling patterns.