Commit 2c31baaa authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

gstreamer: Implement Add<u32> for gst::TypeFindProbability and fix comparison

While the enum is a signed integer, all operations inside GStreamer
(especially comparison) is based on unsigned integers.
parent 620a9b2a
...@@ -235,7 +235,7 @@ status = "generate" ...@@ -235,7 +235,7 @@ status = "generate"
name = "Gst.TypeFindProbability" name = "Gst.TypeFindProbability"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Debug, PartialEq, Eq, Hash" name = "Debug"
[[object]] [[object]]
name = "Gst.EventType" name = "Gst.EventType"
......
...@@ -2848,7 +2848,7 @@ impl SetValue for TocScope { ...@@ -2848,7 +2848,7 @@ impl SetValue for TocScope {
} }
} }
#[derive(Debug, PartialEq, Eq, Hash)] #[derive(Debug)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum TypeFindProbability { pub enum TypeFindProbability {
None, None,
......
...@@ -385,15 +385,55 @@ impl From<Result<ClockSuccess, ClockError>> for ClockReturn { ...@@ -385,15 +385,55 @@ impl From<Result<ClockSuccess, ClockError>> for ClockReturn {
} }
} }
impl PartialEq for ::TypeFindProbability {
fn eq(&self, other: &::TypeFindProbability) -> bool {
(self.to_glib() as u32).eq(&(other.to_glib() as u32))
}
}
impl Eq for ::TypeFindProbability {}
impl PartialOrd for ::TypeFindProbability { impl PartialOrd for ::TypeFindProbability {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.to_glib().partial_cmp(&other.to_glib()) (self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32))
} }
} }
impl Ord for ::TypeFindProbability { impl Ord for ::TypeFindProbability {
fn cmp(&self, other: &Self) -> cmp::Ordering { fn cmp(&self, other: &Self) -> cmp::Ordering {
self.to_glib().cmp(&other.to_glib()) (self.to_glib() as u32).cmp(&(other.to_glib() as u32))
}
}
impl ops::Add<u32> for ::TypeFindProbability {
type Output = ::TypeFindProbability;
fn add(self, rhs: u32) -> ::TypeFindProbability {
let res = (self.to_glib() as u32).saturating_add(rhs);
from_glib(res as i32)
}
}
impl ops::AddAssign<u32> for ::TypeFindProbability {
fn add_assign(&mut self, rhs: u32) {
let res = (self.to_glib() as u32).saturating_add(rhs);
*self = from_glib(res as i32);
}
}
impl ops::Sub<u32> for ::TypeFindProbability {
type Output = ::TypeFindProbability;
fn sub(self, rhs: u32) -> ::TypeFindProbability {
let res = (self.to_glib() as u32).saturating_sub(rhs);
from_glib(res as i32)
}
}
impl ops::SubAssign<u32> for ::TypeFindProbability {
fn sub_assign(&mut self, rhs: u32) {
let res = (self.to_glib() as u32).saturating_sub(rhs);
*self = from_glib(res as i32);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment