use std::ops::{Add, Sub, Mul, Div, AddAssign}; #[derive(Clone, Copy, Debug)] pub struct State { pub q: T, pub p: T, } pub trait Hamiltonian { fn energy(&self) -> f64; fn dots(&self) -> Self; } impl> Add for State { type Output = Self; fn add(self, rhs: Self) -> Self { Self { q: self.q + rhs.q, p: self.p + rhs.p, } } } impl> Sub for State { type Output = Self; fn sub(self, rhs: Self) -> Self { Self { q: self.q - rhs.q, p: self.p - rhs.p, } } } impl> Mul for State { type Output = Self; fn mul(self, rhs: f64) -> Self { Self { q: self.q * rhs, p: self.p * rhs, } } } impl> Div for State { type Output = Self; fn div(self, rhs: f64) -> Self { Self { q: self.q / rhs, p: self.p / rhs, } } } impl AddAssign for State { fn add_assign(&mut self, other: Self) { self.q += other.q; self.p += other.p; } }