RFC: use a `Signed` wrapper for function returning the sign as an integer
Functions such as Segment::to_running_time_full
replicate the C signature for the return type: an integer indicates whether the resulting value must be interpreted as positive or negative. In Rust, alternatives are usually represented using an enum
.
Instead of:
// Declaration
pub fn to_running_time_full(
&self,
position: impl CompatibleFormattedValue<T>,
) -> (i32, T::FullRange);
// Call site
let end_pts = match segment.to_running_time_full(end_pts_position) {
(_, None) => // undefined,
(pts_signum, _) if pts_signum < 0 => // negative,
(_, Some(pts)) => // positive,
};
I propose using:
// Declaration
pub fn to_running_time_full(
&self,
position: impl CompatibleFormattedValue<T>,
) -> gst::Signed<T::FullRange>;
// Call site
use gst::Signed::*;
let end_pts = match segment.to_running_time_full(end_pts_position) {
None => // undefined,
Negative(_) => // negative,
Positive(_) => // positive,
};
We could implement a function Signed::factor
that would return None
, Some(1i32)
or Some(-1i32)
for use in multiplications with an integer and of course the is_none
, is_positive
and is_negative
accessors.