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`.
This commit is contained in:
François Laignel 2022-09-22 00:05:28 +02:00
parent 86549dc06e
commit 99e344af4d
3 changed files with 13 additions and 42 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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<RHS: Borrow<$name>> ops::$op<RHS> 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<RHS: Borrow<$name>> ops::$op<RHS> for &$name {
type Output = $name;
fn $op_name(self, rhs: RHS) -> Self::Output {
(*self).$op_name(rhs)
}
}
impl<RHS: Borrow<$name>> ops::$op_assign<RHS> 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<ND: Borrow<$inner_type>> MulDiv<ND> for $name {
impl MulDiv<$inner_type> for $name {
type Output = $name;
fn mul_div_floor(self, num: ND, denom: ND) -> Option<Self::Output> {
fn mul_div_floor(self, num: $inner_type, denom: $inner_type) -> Option<Self::Output> {
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<Self::Output> {
fn mul_div_round(self, num: $inner_type, denom: $inner_type) -> Option<Self::Output> {
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<Self::Output> {
fn mul_div_ceil(self, num: $inner_type, denom: $inner_type) -> Option<Self::Output> {
self.0
.mul_div_ceil(*num.borrow(), *denom.borrow())
.mul_div_ceil(num, denom)
.map($name)
}
}