1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use super::super::math::gcd;
use super::super::traits::additive;
use super::super::traits::binop;
use std::fmt::Debug;

use additive::Zero;
use binop::{Associative, Commutative, Identity, Magma};
use gcd::Gcd;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum OpGcd<T> {
    OpGcdV,
    _Marker(T),
}
pub use OpGcd::OpGcdV;

impl<T> Default for OpGcd<T> {
    fn default() -> Self { OpGcdV }
}

impl<T> Magma for OpGcd<T>
where
    T: Gcd + Eq + Sized,
{
    type Set = T;
    fn op(&self, x: Self::Set, y: Self::Set) -> Self::Set { x.gcd(y) }
}
impl<T> Identity for OpGcd<T>
where
    T: Gcd + Eq + Zero + Sized,
{
    fn id(&self) -> Self::Set { T::zero() }
}

impl<T> Associative for OpGcd<T> where T: Gcd + Eq + Sized {}
impl<T> Commutative for OpGcd<T> where T: Gcd + Eq + Sized {}