From 99e344af4dfad0c3775ab269a6f9fadd123a0f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Thu, 22 Sep 2022 00:05:28 +0200 Subject: [PATCH] gst/format: simplify some ops impl The `SpecificFormattedValue` types are newtypes of `u64` or `u32` and they all implement `Copy`. It shouldn't be needed to implement operations on `&Type` nor `&inner_type`. --- gstreamer/src/clock_time.rs | 4 --- gstreamer/src/format.rs | 1 - gstreamer/src/macros.rs | 50 ++++++++++--------------------------- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/gstreamer/src/clock_time.rs b/gstreamer/src/clock_time.rs index ee74ac8bf..d9a0347ae 100644 --- a/gstreamer/src/clock_time.rs +++ b/gstreamer/src/clock_time.rs @@ -5,7 +5,6 @@ use glib::StaticType; use muldiv::MulDiv; use num_integer::div_rem; use opt_ops::prelude::*; -use std::borrow::Borrow; use std::io::{self, prelude::*}; use std::ops; use std::time::Duration; @@ -472,13 +471,10 @@ mod tests { #[allow(clippy::eq_op, clippy::op_ref)] fn ops() { assert_eq!(CT_10 + CT_20, CT_30); - assert_eq!(CT_10 + &CT_20, CT_30); - assert_eq!(&CT_10 + &CT_20, CT_30); assert_eq!(CT_30 - CT_20, CT_10); assert_eq!(CT_30 - CT_30, ClockTime::ZERO); assert_eq!(CT_10 * 3, CT_30); assert_eq!(3 * CT_10, CT_30); - assert_eq!(3 * &CT_10, CT_30); assert_eq!(CT_30.nseconds(), 30); assert_eq!(P_CT_1 + P_CT_2, P_CT_3); diff --git a/gstreamer/src/format.rs b/gstreamer/src/format.rs index cd0d0ad6c..52a71789f 100644 --- a/gstreamer/src/format.rs +++ b/gstreamer/src/format.rs @@ -6,7 +6,6 @@ use crate::Format; use glib::translate::{FromGlib, GlibNoneError, IntoGlib, OptionIntoGlib, TryFromGlib}; use muldiv::MulDiv; use opt_ops::prelude::*; -use std::borrow::Borrow; use std::fmt; use std::ops; use thiserror::Error; diff --git a/gstreamer/src/macros.rs b/gstreamer/src/macros.rs index 01c899c0a..cc9a08359 100644 --- a/gstreamer/src/macros.rs +++ b/gstreamer/src/macros.rs @@ -2,25 +2,17 @@ macro_rules! impl_trait_op_same( ($name:ident, $op:ident, $op_name:ident, $op_assign:ident, $op_assign_name:ident) => { - impl> ops::$op for $name { + impl ops::$op<$name> for $name { type Output = Self; - fn $op_name(self, rhs: RHS) -> Self::Output { - Self(self.0.$op_name(rhs.borrow().0)) + fn $op_name(self, rhs: $name) -> Self::Output { + Self(self.0.$op_name(rhs.0)) } } - impl> ops::$op for &$name { - type Output = $name; - - fn $op_name(self, rhs: RHS) -> Self::Output { - (*self).$op_name(rhs) - } - } - - impl> ops::$op_assign for $name { - fn $op_assign_name(&mut self, rhs: RHS) { - self.0.$op_assign_name(rhs.borrow().0) + impl ops::$op_assign<$name> for $name { + fn $op_assign_name(&mut self, rhs: $name) { + self.0.$op_assign_name(rhs.0) } } }; @@ -114,14 +106,6 @@ macro_rules! impl_trait_op_inner_type( } } - impl ops::$op<$inner_type> for &$name { - type Output = $name; - - fn $op_name(self, rhs: $inner_type) -> Self::Output { - (*self).$op_name(rhs) - } - } - impl ops::$op<$name> for $inner_type { type Output = $name; @@ -130,14 +114,6 @@ macro_rules! impl_trait_op_inner_type( } } - impl ops::$op<&$name> for $inner_type { - type Output = $name; - - fn $op_name(self, rhs: &$name) -> $name { - self.$op_name(*rhs) - } - } - impl ops::$op_assign<$inner_type> for $name { fn $op_assign_name(&mut self, rhs: $inner_type) { self.0.$op_assign_name(rhs) @@ -274,24 +250,24 @@ macro_rules! impl_common_ops_for_newtype_uint( impl_unsigned_int_into_signed!($name); impl_signed_ops!($name, $inner_type, $name::ZERO); - impl> MulDiv for $name { + impl MulDiv<$inner_type> for $name { type Output = $name; - fn mul_div_floor(self, num: ND, denom: ND) -> Option { + fn mul_div_floor(self, num: $inner_type, denom: $inner_type) -> Option { self.0 - .mul_div_floor(*num.borrow(), *denom.borrow()) + .mul_div_floor(num, denom) .map($name) } - fn mul_div_round(self, num: ND, denom: ND) -> Option { + fn mul_div_round(self, num: $inner_type, denom: $inner_type) -> Option { self.0 - .mul_div_round(*num.borrow(), *denom.borrow()) + .mul_div_round(num, denom) .map($name) } - fn mul_div_ceil(self, num: ND, denom: ND) -> Option { + fn mul_div_ceil(self, num: $inner_type, denom: $inner_type) -> Option { self.0 - .mul_div_ceil(*num.borrow(), *denom.borrow()) + .mul_div_ceil(num, denom) .map($name) } }