Enhancement: prefer simpler code patterns over shorter ones that require advanced rust knowledge
One of the purposes of the Rust bindings and other GStreamer Rust code such as plugins is to (eventually) replace C as the implementation language, since it's a terrible language. Towards that end, it is important that the code be approachable for C developers.
A lot of patterns in Rust are quite friendly to C programmers, but it is too easy to write code that is succinct and beautiful that's actually very hard to decipher for people who haven't spent 1-2 years writing Rust. This is one of the biggest complaints that I have heard from C developers trying to read GStreamer Rust code.
For instance:
let max_latency = max
.zip(max_latency)
.map(|(max, max_latency)| max.min(max_latency))
.or(max);
This requires you to know: let
Option
zip
map
or
min
. Whereas this:
let max_latency = if let (Some(max), Some(max_latency)) = (max, max_latency) {
Some(max.min(max_latency))
} else {
max
};
Only requires you to know: let
Option
and destructuring.
In this specific case, it may even be a good idea to think about methods on gst::ClockTime
that can make this pattern easier to write and read.
In general, Rust Destructuring is quite powerful and also easy for newbies to wrap their heads around. There are other such Rust features that are both powerful and easier to understand, and we should prefer using those.