-pub trait FiniteNimberBaseInteger : std::ops::BitXor + Sized {
- type Owned;
+use std::fmt::Debug;
+
+pub trait FiniteNimberBase : std::ops::BitXor<Output=Self> + Clone + Eq + Debug + Sized {
+ type Owned: FiniteNimberBase;
+
+ fn to_owned(self) -> Self::Owned;
+}
+
+impl FiniteNimberBase for u64 {
+ type Owned = Self;
+
+ fn to_owned(self) -> Self::Owned {self}
}
-pub struct FiniteNimber<T: FiniteNimberBaseInteger> {
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct FiniteNimber<T: FiniteNimberBase> {
n: T,
}
+
+impl<T: FiniteNimberBase> FiniteNimber<T> {
+ pub fn new(n: T) -> Self {
+ Self { n }
+ }
+}
+
+impl<T: FiniteNimberBase> std::ops::Add<FiniteNimber<T>> for FiniteNimber<T> {
+ type Output = FiniteNimber<T::Owned>;
+
+ fn add(self, other: Self) -> Self::Output {
+ Self::Output::new((self.n ^ other.n).to_owned())
+ }
+}
mod finitenimber;
pub use finitenimber::FiniteNimber;
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn addition() {
+ let a = FiniteNimber::new(0b1100u64);
+ let b = FiniteNimber::new(0b1010u64);
+ assert_eq!(a + b, FiniteNimber::new(0b0110u64));
+ }
+}