1use super::super::traits::additive;
4use super::super::traits::binop;
5
6use std::fmt::Debug;
7
8use additive::{AddAssoc, AddComm, Zero};
9use binop::{Associative, Commutative, Identity, Magma, PartialRecip, Recip};
10
11#[derive(Clone, Copy, Debug, Eq, PartialEq)]
21pub enum OpAdd<T> {
22 OpAddV,
23 _Marker(T),
24}
25pub use OpAdd::OpAddV;
26
27impl<T> Default for OpAdd<T> {
28 fn default() -> Self { OpAddV }
29}
30
31use std::ops::{Add, Neg};
32
33impl<T> Magma for OpAdd<T>
34where
35 T: Add<Output = T> + Eq + Sized,
36{
37 type Set = T;
38 fn op(&self, x: Self::Set, y: Self::Set) -> Self::Set { x + y }
39}
40impl<T> Identity for OpAdd<T>
41where
42 T: Add<Output = T> + Eq + Sized + Zero,
43{
44 fn id(&self) -> Self::Set { T::zero() }
45}
46impl<T> PartialRecip for OpAdd<T>
47where
48 T: Add<Output = T> + Eq + Sized + Neg<Output = T>,
49{
50 fn partial_recip(&self, x: Self::Set) -> Option<Self::Set> { Some(-x) }
51}
52impl<T> Recip for OpAdd<T>
53where
54 T: Add<Output = T> + Eq + Sized + Neg<Output = T>,
55{
56 fn recip(&self, x: Self::Set) -> Self::Set { -x }
57}
58impl<T> Associative for OpAdd<T> where T: Add<Output = T> + Eq + Sized + AddAssoc
59{}
60impl<T> Commutative for OpAdd<T> where T: Add<Output = T> + Eq + Sized + AddComm {}