Skip to main content

nekolib/utils/
op_add_count.rs

1//! 加法に関する wrapper クラス。
2
3use 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};
10
11#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12pub enum OpAddCount<T> {
13    OpAddCountV,
14    _Marker(T),
15}
16pub use OpAddCount::OpAddCountV;
17
18impl<T> Default for OpAddCount<T> {
19    fn default() -> Self { OpAddCountV }
20}
21
22use std::ops::Add;
23
24impl<T> Magma for OpAddCount<T>
25where
26    T: Add<Output = T> + Eq + Sized,
27{
28    type Set = (T, T);
29    fn op(&self, (xv, xc): Self::Set, (yv, yc): Self::Set) -> Self::Set {
30        (xv + yv, xc + yc)
31    }
32}
33impl<T> Identity for OpAddCount<T>
34where
35    T: Add<Output = T> + Eq + Sized + Zero,
36{
37    fn id(&self) -> Self::Set { (T::zero(), T::zero()) }
38}
39impl<T> Associative for OpAddCount<T> where
40    T: Add<Output = T> + Eq + Sized + AddAssoc
41{
42}
43impl<T> Commutative for OpAddCount<T> where
44    T: Add<Output = T> + Eq + Sized + AddComm
45{
46}