From a2210055dbf4b9d24be8651525afbda76569e42b Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Wed, 2 Jan 2019 19:41:12 +0100 Subject: [PATCH] Added Ratable implementation for &'a T and &'a mut T. --- src/gaussian.rs | 2 +- src/lib.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/gaussian.rs b/src/gaussian.rs index 0308933..762c101 100644 --- a/src/gaussian.rs +++ b/src/gaussian.rs @@ -41,7 +41,7 @@ impl Gaussian { pub fn mu(&self) -> f64 { if self.pi == 0.0 { - return 0.0; + 0.0 } else { self.tau / self.pi } diff --git a/src/lib.rs b/src/lib.rs index da8fda0..d24365a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,36 @@ pub trait Rateable { } } +impl<'a, T> Rateable for &'a T +where + T: Rateable, +{ + #[inline] + fn mu(&self) -> f64 { + T::mu(self) + } + + #[inline] + fn sigma(&self) -> f64 { + T::sigma(self) + } +} + +impl<'a, T> Rateable for &'a mut T +where + T: Rateable, +{ + #[inline] + fn mu(&self) -> f64 { + T::mu(self) + } + + #[inline] + fn sigma(&self) -> f64 { + T::sigma(self) + } +} + pub trait RateableMut { fn mu_mut(&mut self) -> &mut f64; fn sigma_mut(&mut self) -> &mut f64;