Proper error handling in examples
All the unwrap()s are ugly and we can easily do better.
Idea would be to have main
be a function that just calls run
or a couple of other functions returning a Result<_,_>
and it's only job is to destructure that and print any possible errors.
For each example we would then define an error enum (that implements Display
, Error
and what else) like
enum MyLittleError {
MissingElement(&str),
LinkingFailed(&str, &str),
Other(&str),
}
and return those from the functions, ideally making use of the ?-operator and various Option<_>
/ Result<_, _>
combinators, e.g. gst::ElementFactory::make("appsrc", None).ok_or(MyLittleError::MissingElement("appsrc"))?;
.