]> git.lizzy.rs Git - rust.git/blobdiff - src/librand/distributions/exponential.rs
Add missing Debug implementation for librand structs
[rust.git] / src / librand / distributions / exponential.rs
index 5a8558efc024437b82300161ec3133c147795a8a..3337cc2a6273cf78731a7ad12b3f2ef46e91b543 100644 (file)
@@ -10,6 +10,8 @@
 
 //! The exponential distribution.
 
+use core::fmt;
+
 #[cfg(not(test))] // only necessary for no_std
 use FloatMath;
 
@@ -55,6 +57,14 @@ fn zero_case<R: Rng>(rng: &mut R, _u: f64) -> f64 {
     }
 }
 
+impl fmt::Debug for Exp1 {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_tuple("Exp1")
+         .field(&self.0)
+         .finish()
+    }
+}
+
 /// The exponential distribution `Exp(lambda)`.
 ///
 /// This distribution has density function: `f(x) = lambda *
@@ -79,6 +89,7 @@ fn sample<R: Rng>(&mut self, rng: &mut R) -> f64 {
         self.ind_sample(rng)
     }
 }
+
 impl IndependentSample<f64> for Exp {
     fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
         let Exp1(n) = rng.gen::<Exp1>();
@@ -86,6 +97,14 @@ fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
     }
 }
 
+impl fmt::Debug for Exp {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_struct("Exp")
+         .field("lambda_inverse", &self.lambda_inverse)
+         .finish()
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use distributions::{IndependentSample, Sample};