gstreamer/format,value: Use Self in more places

This commit is contained in:
Marijn Suijten 2021-01-08 11:43:18 +01:00
parent 9890803cc6
commit 4cb6b64e2d
2 changed files with 39 additions and 39 deletions

View file

@ -136,7 +136,7 @@ macro_rules! impl_op_same(
impl ops::$op<$name> for $name {
type Output = $name;
fn $op_name(self, other: $name) -> $name {
fn $op_name(self, other: $name) -> Self::Output {
match (self.0, other.0) {
(Some(a), Some(b)) => $name($e(a, b)),
_ => $name(None),
@ -147,7 +147,7 @@ macro_rules! impl_op_same(
impl<'a> ops::$op<&'a $name> for $name {
type Output = $name;
fn $op_name(self, other: &'a $name) -> $name {
fn $op_name(self, other: &'a $name) -> Self::Output {
self.$op_name(*other)
}
}
@ -155,7 +155,7 @@ macro_rules! impl_op_same(
impl<'a> ops::$op<$name> for &'a $name {
type Output = $name;
fn $op_name(self, other: $name) -> $name {
fn $op_name(self, other: $name) -> Self::Output {
(*self).$op_name(other)
}
}
@ -163,7 +163,7 @@ macro_rules! impl_op_same(
impl<'a, 'b> ops::$op<&'a $name> for &'b $name {
type Output = $name;
fn $op_name(self, other: &'a $name) -> $name {
fn $op_name(self, other: &'a $name) -> Self::Output {
(*self).$op_name(*other)
}
}
@ -190,7 +190,7 @@ macro_rules! impl_op_u64(
impl ops::$op<u64> for $name {
type Output = $name;
fn $op_name(self, other: u64) -> $name {
fn $op_name(self, other: u64) -> Self::Output {
match self.0 {
Some(a) => $name($e(a, other)),
_ => $name(None),
@ -201,7 +201,7 @@ macro_rules! impl_op_u64(
impl<'a> ops::$op<&'a u64> for $name {
type Output = $name;
fn $op_name(self, other: &'a u64) -> $name {
fn $op_name(self, other: &'a u64) -> Self::Output {
self.$op_name(*other)
}
}
@ -209,7 +209,7 @@ macro_rules! impl_op_u64(
impl<'a> ops::$op<u64> for &'a $name {
type Output = $name;
fn $op_name(self, other: u64) -> $name {
fn $op_name(self, other: u64) -> Self::Output {
(*self).$op_name(other)
}
}
@ -217,7 +217,7 @@ macro_rules! impl_op_u64(
impl<'a, 'b> ops::$op<&'a u64> for &'b $name {
type Output = $name;
fn $op_name(self, other: &'a u64) -> $name {
fn $op_name(self, other: &'a u64) -> Self::Output {
self.$op_name(*other)
}
}
@ -297,7 +297,7 @@ macro_rules! impl_format_value_traits(
}
impl From<$name> for GenericFormattedValue {
fn from(v: $name) -> GenericFormattedValue {
fn from(v: $name) -> Self {
skip_assert_initialized!();
GenericFormattedValue::$format_value(v)
}
@ -306,7 +306,7 @@ macro_rules! impl_format_value_traits(
impl TryFrom<GenericFormattedValue> for $name {
type Error = TryFromGenericFormattedValueError;
fn try_from(v: GenericFormattedValue) -> Result<$name, TryFromGenericFormattedValueError> {
fn try_from(v: GenericFormattedValue) -> Result<$name, Self::Error> {
skip_assert_initialized!();
if let GenericFormattedValue::$format_value(v) = v {
Ok(v)
@ -319,14 +319,14 @@ macro_rules! impl_format_value_traits(
impl SpecificFormattedValue for $name { }
impl From<u64> for $name {
fn from(v: u64) -> $name {
fn from(v: u64) -> Self {
skip_assert_initialized!();
$name(Some(v))
}
}
impl From<Option<u64>> for $name {
fn from(v: Option<u64>) -> $name {
fn from(v: Option<u64>) -> Self {
skip_assert_initialized!();
$name(v)
}
@ -538,7 +538,7 @@ impl FormattedValue for Undefined {
}
impl From<Undefined> for GenericFormattedValue {
fn from(v: Undefined) -> GenericFormattedValue {
fn from(v: Undefined) -> Self {
skip_assert_initialized!();
GenericFormattedValue::Undefined(v)
}
@ -560,7 +560,7 @@ impl TryFrom<GenericFormattedValue> for Undefined {
impl SpecificFormattedValue for Undefined {}
impl From<i64> for Undefined {
fn from(v: i64) -> Undefined {
fn from(v: i64) -> Self {
skip_assert_initialized!();
Undefined(v)
}
@ -622,7 +622,7 @@ impl FormattedValue for Percent {
}
impl From<Percent> for GenericFormattedValue {
fn from(v: Percent) -> GenericFormattedValue {
fn from(v: Percent) -> Self {
skip_assert_initialized!();
GenericFormattedValue::Percent(v)
}

View file

@ -14,17 +14,17 @@ use glib::value::{FromValue, FromValueOptional, SetValue, ToSendValue, Value};
pub struct Fraction(pub Rational32);
impl Fraction {
pub fn new(num: i32, den: i32) -> Fraction {
pub fn new(num: i32, den: i32) -> Self {
assert_initialized_main_thread!();
(num, den).into()
}
pub fn approximate_f32(x: f32) -> Option<Fraction> {
pub fn approximate_f32(x: f32) -> Option<Self> {
assert_initialized_main_thread!();
Rational32::approximate_float(x).map(|r| r.into())
}
pub fn approximate_f64(x: f64) -> Option<Fraction> {
pub fn approximate_f64(x: f64) -> Option<Self> {
assert_initialized_main_thread!();
Rational32::approximate_float(x).map(|r| r.into())
}
@ -39,7 +39,7 @@ impl fmt::Display for Fraction {
impl ops::Deref for Fraction {
type Target = Rational32;
fn deref(&self) -> &Rational32 {
fn deref(&self) -> &Self::Target {
&self.0
}
}
@ -61,7 +61,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<Fraction> for Fraction {
type Output = Fraction;
fn $f(self, other: Fraction) -> Fraction {
fn $f(self, other: Fraction) -> Self::Output {
Fraction((self.0).$f(other.0))
}
}
@ -69,7 +69,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<Fraction> for &Fraction {
type Output = Fraction;
fn $f(self, other: Fraction) -> Fraction {
fn $f(self, other: Fraction) -> Self::Output {
Fraction((self.0).$f(other.0))
}
}
@ -77,7 +77,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<&Fraction> for Fraction {
type Output = Fraction;
fn $f(self, other: &Fraction) -> Fraction {
fn $f(self, other: &Fraction) -> Self::Output {
Fraction((self.0).$f(other.0))
}
}
@ -85,7 +85,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<&Fraction> for &Fraction {
type Output = Fraction;
fn $f(self, other: &Fraction) -> Fraction {
fn $f(self, other: &Fraction) -> Self::Output {
Fraction((self.0).$f(other.0))
}
}
@ -93,7 +93,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<i32> for Fraction {
type Output = Fraction;
fn $f(self, other: i32) -> Fraction {
fn $f(self, other: i32) -> Self::Output {
self.$f(Fraction::from(other))
}
}
@ -101,7 +101,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<i32> for &Fraction {
type Output = Fraction;
fn $f(self, other: i32) -> Fraction {
fn $f(self, other: i32) -> Self::Output {
self.$f(Fraction::from(other))
}
}
@ -109,7 +109,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<&i32> for Fraction {
type Output = Fraction;
fn $f(self, other: &i32) -> Fraction {
fn $f(self, other: &i32) -> Self::Output {
self.$f(Fraction::from(*other))
}
}
@ -117,7 +117,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<&i32> for &Fraction {
type Output = Fraction;
fn $f(self, other: &i32) -> Fraction {
fn $f(self, other: &i32) -> Self::Output {
self.$f(Fraction::from(*other))
}
}
@ -125,7 +125,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<Fraction> for i32 {
type Output = Fraction;
fn $f(self, other: Fraction) -> Fraction {
fn $f(self, other: Fraction) -> Self::Output {
Fraction::from(self).$f(other)
}
}
@ -133,7 +133,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<&Fraction> for i32 {
type Output = Fraction;
fn $f(self, other: &Fraction) -> Fraction {
fn $f(self, other: &Fraction) -> Self::Output {
Fraction::from(self).$f(other)
}
}
@ -141,7 +141,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<Fraction> for &i32 {
type Output = Fraction;
fn $f(self, other: Fraction) -> Fraction {
fn $f(self, other: Fraction) -> Self::Output {
Fraction::from(*self).$f(other)
}
}
@ -149,7 +149,7 @@ macro_rules! impl_fraction_binop {
impl ops::$name<&Fraction> for &i32 {
type Output = Fraction;
fn $f(self, other: &Fraction) -> Fraction {
fn $f(self, other: &Fraction) -> Self::Output {
Fraction::from(*self).$f(other)
}
}
@ -189,7 +189,7 @@ impl_fraction_binop!(Rem, rem, RemAssign, rem_assign);
impl ops::Neg for Fraction {
type Output = Fraction;
fn neg(self) -> Fraction {
fn neg(self) -> Self::Output {
Fraction(self.0.neg())
}
}
@ -197,20 +197,20 @@ impl ops::Neg for Fraction {
impl ops::Neg for &Fraction {
type Output = Fraction;
fn neg(self) -> Fraction {
fn neg(self) -> Self::Output {
Fraction(self.0.neg())
}
}
impl From<i32> for Fraction {
fn from(x: i32) -> Fraction {
fn from(x: i32) -> Self {
assert_initialized_main_thread!();
Fraction(x.into())
}
}
impl From<(i32, i32)> for Fraction {
fn from(x: (i32, i32)) -> Fraction {
fn from(x: (i32, i32)) -> Self {
assert_initialized_main_thread!();
Fraction(x.into())
}
@ -223,14 +223,14 @@ impl From<Fraction> for (i32, i32) {
}
impl From<Rational32> for Fraction {
fn from(x: Rational32) -> Fraction {
fn from(x: Rational32) -> Self {
assert_initialized_main_thread!();
Fraction(x)
}
}
impl From<Fraction> for Rational32 {
fn from(x: Fraction) -> Rational32 {
fn from(x: Fraction) -> Self {
skip_assert_initialized!();
x.0
}
@ -243,7 +243,7 @@ impl glib::types::StaticType for Fraction {
}
impl<'a> FromValue<'a> for Fraction {
unsafe fn from_value(v: &'a Value) -> Fraction {
unsafe fn from_value(v: &'a Value) -> Self {
let n = ffi::gst_value_get_fraction_numerator(v.to_glib_none().0);
let d = ffi::gst_value_get_fraction_denominator(v.to_glib_none().0);
@ -252,7 +252,7 @@ impl<'a> FromValue<'a> for Fraction {
}
impl<'a> FromValueOptional<'a> for Fraction {
unsafe fn from_value_optional(v: &'a Value) -> Option<Fraction> {
unsafe fn from_value_optional(v: &'a Value) -> Option<Self> {
Some(Fraction::from_value(v))
}
}