From 620a9b2a9508640ebf69d30052cb68f8bb6a9dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 4 Jun 2019 10:21:26 +0300 Subject: [PATCH] gstreamer: Implement Add for gst::Rank and fix comparison While the enum is a signed integer, all operations inside GStreamer (especially comparison) is based on unsigned integers. --- Gir_Gst.toml | 2 +- gstreamer/src/auto/enums.rs | 2 +- gstreamer/src/enums.rs | 46 ++++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Gir_Gst.toml b/Gir_Gst.toml index b07da7188..99dbd81f4 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -229,7 +229,7 @@ status = "generate" name = "Gst.Rank" status = "generate" [[object.derive]] - name = "Debug, PartialEq, Eq, Hash" + name = "Debug" [[object]] name = "Gst.TypeFindProbability" diff --git a/gstreamer/src/auto/enums.rs b/gstreamer/src/auto/enums.rs index 4647b30ac..bf07cf47b 100644 --- a/gstreamer/src/auto/enums.rs +++ b/gstreamer/src/auto/enums.rs @@ -1657,7 +1657,7 @@ impl SetValue for QOSType { } } - #[derive(Debug, PartialEq, Eq, Hash)] + #[derive(Debug)] #[derive(Clone, Copy)] pub enum Rank { None, diff --git a/gstreamer/src/enums.rs b/gstreamer/src/enums.rs index e56e8283d..6911128b3 100644 --- a/gstreamer/src/enums.rs +++ b/gstreamer/src/enums.rs @@ -6,9 +6,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cmp; use std::error::Error; use std::fmt; +use std::{cmp, ops}; use ClockReturn; use FlowReturn; use PadLinkReturn; @@ -397,15 +397,55 @@ impl Ord for ::TypeFindProbability { } } +impl PartialEq for ::Rank { + fn eq(&self, other: &::Rank) -> bool { + (self.to_glib() as u32).eq(&(other.to_glib() as u32)) + } +} + +impl Eq for ::Rank {} + impl PartialOrd for ::Rank { fn partial_cmp(&self, other: &Self) -> Option { - self.to_glib().partial_cmp(&other.to_glib()) + (self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32)) } } impl Ord for ::Rank { 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 for ::Rank { + type Output = ::Rank; + + fn add(self, rhs: u32) -> ::Rank { + let res = (self.to_glib() as u32).saturating_add(rhs); + from_glib(res as i32) + } +} + +impl ops::AddAssign for ::Rank { + 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 for ::Rank { + type Output = ::Rank; + + fn sub(self, rhs: u32) -> ::Rank { + let res = (self.to_glib() as u32).saturating_sub(rhs); + from_glib(res as i32) + } +} + +impl ops::SubAssign for ::Rank { + fn sub_assign(&mut self, rhs: u32) { + let res = (self.to_glib() as u32).saturating_sub(rhs); + *self = from_glib(res as i32); } }