Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing rand::Rand #14

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ features = ["std"]
optional = true
version = "1.0"

[dependencies.rand]
optional = true
version = "0.4"

[features]
default = []
unstable = []
5 changes: 4 additions & 1 deletion ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ cargo build --no-default-features
cargo test --no-default-features

# Each isolated feature should also work everywhere.
for feature in serde; do
for feature in rand serde; do
cargo build --verbose --no-default-features --features="$feature"
cargo test --verbose --no-default-features --features="$feature"
done

cargo build --all-features
cargo test --all-features
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ extern crate num_traits as traits;
#[cfg(feature = "serde")]
extern crate serde;

#[cfg(feature = "rand")]
extern crate rand;

use std::error::Error;
use std::fmt;
#[cfg(test)]
Expand Down Expand Up @@ -1117,6 +1120,15 @@ impl<'de, T> serde::Deserialize<'de> for Complex<T> where
}
}

#[cfg(feature = "rand")]
impl<T> rand::Rand for Complex<T> where
T: rand::Rand + Num + Clone
{
fn rand<R:rand::Rng>(rng: &mut R) -> Self {
Self::new(rng.gen::<T>(), rng.gen::<T>())
}
}

#[derive(Debug, PartialEq)]
pub struct ParseComplexError<E>
{
Expand Down