gst/format: some more improvements and fixes
Please note that the 3d commit calls for discussion.
- Cleanup format related re-exports in
gst/lib.rs
and reduce the impact on theprelude
. I used to stuff every single trait there even those which were internally resolved. See the resulting changes inlib.rs
. Besides theprelude
, I decided not to re-export the traits under the maingst
module because they are rarely used. APIs need to refer to e.g.gst::format::FormattedValue
instead ofgst::FormattedValue
, or justuse gst::format::FormattedValue;
to getFormattedValue
. - The
GST_FORMAT_PERCENT_SCALE
constant was not used to compute the value to display. I took this opportunity to add examples showing how to formatPercent
display. - I noticed the specific formatted values still exposed their inner value as
pub
. This is convenient in practice, but users are easily able to build, say aDefault(u64::MAX)
, which when passed to C would be considered as theNone
variant of this format. This is something that has been removed fromClockTime
for quite some times. Users can build values using the constructors such asfrom_seconds
or using operations such as10 * gst::ClockTime::SECOND
. Getting the value as plain integer is just one deref away (e.g.*duration
). So in this 3d commit, I proceeded to remove thepub
specifier from the remaining specific formatted values and added constants to help building those. Users can write10 * Buffers::ONE
or512 * Bytes::K
for instance. I added examples to help users discover what can be used to build values. Impact on existing code ingstreamer-rs
andgst-plugins-rs
is OK IMO. But then I realized that this doesn't actually solve the problem: users can still callu64::MAX * Buffers::ONE
which from a C perspective isNone
. Of course, I don't think checking the result of each operation would be a good move performance-wise. I guess the only obvious workaround for this would be to check the value before calling in a C API (e.g. inFormattedValue::into_raw_value
&IntoGlib
implementations). But then, would it be worth removing thepub
specifier? We can still keep the new constants anyway.