From 610f6cae6a859479fde9913475dc67b044eaf260 Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Mon, 8 Jul 2019 16:57:53 +0200 Subject: [PATCH] Clean up doctests Also make sure that the macros work when they are imported in isolation. --- src/histogram.rs | 10 ++-------- src/lib.rs | 10 ---------- src/macros.rs | 12 ++---------- src/moments/mod.rs | 14 +++----------- tests/histogram.rs | 3 --- 5 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/histogram.rs b/src/histogram.rs index b6aa1a1..ebb70ec 100644 --- a/src/histogram.rs +++ b/src/histogram.rs @@ -10,12 +10,7 @@ /// # Example /// /// ``` -/// # extern crate core; -/// # #[macro_use] extern crate average; -/// # #[cfg(feature = "serde1")] #[macro_use] extern crate serde_derive; -/// # #[cfg(feature = "serde1")] #[macro_use] extern crate serde_big_array; -/// # fn main() { -/// use average::Histogram; +/// use average::{Histogram, define_histogram}; /// /// define_histogram!(hist, 10); /// let mut h = hist::Histogram::with_const_width(0., 100.); @@ -23,14 +18,13 @@ /// h.add(i as f64).unwrap(); /// } /// assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]); -/// # } /// ``` #[macro_export] macro_rules! define_histogram { ($name:ident, $LEN:expr) => ( mod $name { use $crate::Histogram as Trait; - #[cfg(feature = "serde1")] big_array! { + #[cfg(feature = "serde1")] serde_big_array::big_array! { BigArray; LEN, (LEN + 1), } diff --git a/src/lib.rs b/src/lib.rs index beae3a5..566dad3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,16 +90,6 @@ #![no_std] - - -#[cfg(feature = "serde1")] -extern crate serde; -#[cfg(feature = "serde1")] -#[macro_use] extern crate serde_derive; -#[cfg(feature = "serde1")] -#[macro_use] extern crate serde_big_array; - - #[macro_use] mod macros; #[macro_use] mod moments; mod weighted_mean; diff --git a/src/macros.rs b/src/macros.rs index 8934148..e18630e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -37,10 +37,7 @@ macro_rules! assert_almost_eq { /// # Examples /// /// ``` -/// # extern crate core; -/// # #[macro_use] extern crate average; -/// # fn main() { -/// use average::{Min, Max, Estimate}; +/// use average::{Min, Max, Estimate, concatenate}; /// /// concatenate!(MinMax, [Min, min], [Max, max]); /// @@ -48,7 +45,6 @@ macro_rules! assert_almost_eq { /// /// assert_eq!(s.min(), 1.0); /// assert_eq!(s.max(), 5.0); -/// # } /// ``` /// /// The generated code looks roughly like this: @@ -85,15 +81,11 @@ macro_rules! assert_almost_eq { /// can do the following: /// /// ``` -/// # extern crate core; -/// # #[macro_use] extern crate average; -/// # fn main() { -/// use average::{Variance, Quantile, Estimate}; +/// use average::{Variance, Quantile, Estimate, concatenate}; /// /// concatenate!(Estimator, /// [Variance, variance, mean, sample_variance], /// [Quantile, quantile, quantile]); -/// # } /// ``` #[macro_export] macro_rules! concatenate { diff --git a/src/moments/mod.rs b/src/moments/mod.rs index 0ef4bf3..81c5633 100644 --- a/src/moments/mod.rs +++ b/src/moments/mod.rs @@ -31,15 +31,8 @@ pub type MeanWithError = Variance; /// # Example /// /// ``` -/// # extern crate core; -/// # extern crate conv; -/// # extern crate num_traits; -/// #[cfg(feature = "serde1")] -/// extern crate serde; -/// #[cfg(feature = "serde1")] -/// #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate average; -/// # fn main() { +/// use average::{define_moments, assert_almost_eq}; +/// /// define_moments!(Moments4, 4); /// /// let mut a: Moments4 = (1..6).map(f64::from).collect(); @@ -56,7 +49,6 @@ pub type MeanWithError = Variance; /// assert_almost_eq!(a.standardized_moment(3), 0.2795084971874741, 1e-15); /// // kurtosis /// assert_almost_eq!(a.standardized_moment(4), -1.365 + 3.0, 1e-14); -/// # } /// ``` #[macro_export] macro_rules! define_moments { @@ -301,6 +293,6 @@ macro_rules! define_moments { } } - impl_from_iterator!($name); + $crate::impl_from_iterator!($name); ); } diff --git a/tests/histogram.rs b/tests/histogram.rs index 8e14fe4..c77d46c 100644 --- a/tests/histogram.rs +++ b/tests/histogram.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "serde1")] -#[macro_use] extern crate serde_big_array; - use core::iter::Iterator; use rand::SeedableRng; use rand_distr::Distribution;