gwrizienn/src/tuple.rs
2025-07-21 19:34:51 +02:00

26 lines
644 B
Rust

use std::ops::{Add, Mul};
use num_traits::Inv;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Tuple<A, B>(pub A, pub B);
impl<A, B> Add for Tuple<A, B> where A: Add<A, Output=A>, B: Add<B, Output=B> {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Self(self.0+rhs.0, self.1+rhs.1)
}
}
impl<A, B> Mul for Tuple<A, B> where A: Mul<A, Output=A>, B: Mul<B, Output=B> {
type Output = Self;
fn mul(self, rhs: Self) -> Self {
Self(self.0*rhs.0, self.1*rhs.1)
}
}
impl<A,B> Inv for Tuple<A, B> where A: Inv<Output=A>, B: Inv<Output=B> {
type Output = Self;
fn inv(self) -> Self {
Self(self.0.inv(), self.1.inv())
}
}