Make rand
dependency optional (but enabled by default)
Most users probably don't use the rand impls, so the `rand` crate pulls a large number of dependencies into the dependency tree which is just wasted compilation time.
This commit is contained in:
parent
93786bfc9a
commit
4bd8ebb38d
7 changed files with 39 additions and 15 deletions
|
@ -17,6 +17,7 @@ keywords = ["gamedev", "math", "matrix", "vector", "quaternion"]
|
||||||
name = "cgmath"
|
name = "cgmath"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["rand"]
|
||||||
unstable = []
|
unstable = []
|
||||||
swizzle = []
|
swizzle = []
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ swizzle = []
|
||||||
approx = "0.3"
|
approx = "0.3"
|
||||||
mint = { version = "0.5", optional = true }
|
mint = { version = "0.5", optional = true }
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
rand = "0.6"
|
rand = { version = "0.6", optional = true }
|
||||||
serde = { version = "1.0", features = ["serde_derive"], optional = true }
|
serde = { version = "1.0", features = ["serde_derive"], optional = true }
|
||||||
simd = { version = "0.2", optional = true }
|
simd = { version = "0.2", optional = true }
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,11 @@ use std::f64;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::*;
|
use std::ops::*;
|
||||||
|
|
||||||
use rand::Rng;
|
#[cfg(feature = "rand")]
|
||||||
use rand::distributions::{Distribution, Standard};
|
use rand::{
|
||||||
use rand::distributions::uniform::SampleUniform;
|
Rng,
|
||||||
|
distributions::{Distribution, Standard, uniform::SampleUniform},
|
||||||
|
};
|
||||||
use num_traits::{cast, Bounded};
|
use num_traits::{cast, Bounded};
|
||||||
|
|
||||||
use structure::*;
|
use structure::*;
|
||||||
|
@ -209,6 +211,7 @@ macro_rules! impl_angle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rand")]
|
||||||
impl<S> Distribution<$Angle<S>> for Standard
|
impl<S> Distribution<$Angle<S>> for Standard
|
||||||
where Standard: Distribution<S>,
|
where Standard: Distribution<S>,
|
||||||
S: BaseFloat + SampleUniform {
|
S: BaseFloat + SampleUniform {
|
||||||
|
|
|
@ -13,8 +13,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use rand::distributions::{Distribution, Standard};
|
#[cfg(feature = "rand")]
|
||||||
use rand::Rng;
|
use rand::{
|
||||||
|
Rng,
|
||||||
|
distributions::{Distribution, Standard},
|
||||||
|
};
|
||||||
use num_traits::cast;
|
use num_traits::cast;
|
||||||
|
|
||||||
use structure::*;
|
use structure::*;
|
||||||
|
@ -186,6 +189,7 @@ impl<A: Angle> approx::UlpsEq for Euler<A> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rand")]
|
||||||
impl<A> Distribution<Euler<A>> for Standard
|
impl<A> Distribution<Euler<A>> for Standard
|
||||||
where Standard: Distribution<A>,
|
where Standard: Distribution<A>,
|
||||||
A: Angle {
|
A: Angle {
|
||||||
|
|
|
@ -58,6 +58,7 @@ extern crate approx;
|
||||||
#[cfg(feature = "mint")]
|
#[cfg(feature = "mint")]
|
||||||
pub extern crate mint;
|
pub extern crate mint;
|
||||||
|
|
||||||
|
#[cfg(feature = "rand")]
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
pub extern crate num_traits;
|
pub extern crate num_traits;
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use rand::distributions::{Standard, Distribution};
|
#[cfg(feature = "rand")]
|
||||||
use rand::Rng;
|
use rand::{
|
||||||
|
Rng,
|
||||||
|
distributions::{Standard, Distribution},
|
||||||
|
};
|
||||||
use num_traits::{cast, NumCast};
|
use num_traits::{cast, NumCast};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
@ -1536,8 +1539,9 @@ impl<S: fmt::Debug> fmt::Debug for Matrix4<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rand")]
|
||||||
impl<S> Distribution<Matrix2<S>> for Standard
|
impl<S> Distribution<Matrix2<S>> for Standard
|
||||||
where
|
where
|
||||||
Standard: Distribution<Vector2<S>>,
|
Standard: Distribution<Vector2<S>>,
|
||||||
S: BaseFloat {
|
S: BaseFloat {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1549,6 +1553,7 @@ impl<S> Distribution<Matrix2<S>> for Standard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rand")]
|
||||||
impl<S> Distribution<Matrix3<S>> for Standard
|
impl<S> Distribution<Matrix3<S>> for Standard
|
||||||
where Standard: Distribution<Vector3<S>>,
|
where Standard: Distribution<Vector3<S>>,
|
||||||
S: BaseFloat {
|
S: BaseFloat {
|
||||||
|
@ -1562,6 +1567,7 @@ impl<S> Distribution<Matrix3<S>> for Standard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rand")]
|
||||||
impl<S> Distribution<Matrix4<S>> for Standard
|
impl<S> Distribution<Matrix4<S>> for Standard
|
||||||
where Standard: Distribution<Vector4<S>>,
|
where Standard: Distribution<Vector4<S>>,
|
||||||
S: BaseFloat {
|
S: BaseFloat {
|
||||||
|
|
|
@ -17,8 +17,11 @@ use std::iter;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::*;
|
use std::ops::*;
|
||||||
|
|
||||||
use rand::distributions::{Distribution, Standard};
|
#[cfg(feature = "rand")]
|
||||||
use rand::Rng;
|
use rand::{
|
||||||
|
Rng,
|
||||||
|
distributions::{Distribution, Standard},
|
||||||
|
};
|
||||||
use num_traits::{cast, NumCast};
|
use num_traits::{cast, NumCast};
|
||||||
|
|
||||||
use structure::*;
|
use structure::*;
|
||||||
|
@ -870,7 +873,8 @@ index_operators!(S, [S], RangeTo<usize>);
|
||||||
index_operators!(S, [S], RangeFrom<usize>);
|
index_operators!(S, [S], RangeFrom<usize>);
|
||||||
index_operators!(S, [S], RangeFull);
|
index_operators!(S, [S], RangeFull);
|
||||||
|
|
||||||
impl<S> Distribution<Quaternion<S>> for Standard
|
#[cfg(feature = "rand")]
|
||||||
|
impl<S> Distribution<Quaternion<S>> for Standard
|
||||||
where Standard: Distribution<S>,
|
where Standard: Distribution<S>,
|
||||||
Standard: Distribution<Vector3<S>>,
|
Standard: Distribution<Vector3<S>>,
|
||||||
S: BaseFloat {
|
S: BaseFloat {
|
||||||
|
|
|
@ -13,8 +13,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use rand::distributions::{Distribution, Standard};
|
#[cfg(feature = "rand")]
|
||||||
use rand::Rng;
|
use rand::{
|
||||||
|
Rng,
|
||||||
|
distributions::{Distribution, Standard},
|
||||||
|
};
|
||||||
use num_traits::{Bounded, NumCast};
|
use num_traits::{Bounded, NumCast};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
@ -245,6 +248,7 @@ macro_rules! impl_vector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rand")]
|
||||||
impl<S> Distribution<$VectorN<S>> for Standard
|
impl<S> Distribution<$VectorN<S>> for Standard
|
||||||
where Standard: Distribution<S>,
|
where Standard: Distribution<S>,
|
||||||
S: BaseFloat {
|
S: BaseFloat {
|
||||||
|
@ -502,7 +506,8 @@ macro_rules! impl_vector_default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Distribution<$VectorN<S>> for Standard
|
#[cfg(feature = "rand")]
|
||||||
|
impl<S> Distribution<$VectorN<S>> for Standard
|
||||||
where S: BaseFloat,
|
where S: BaseFloat,
|
||||||
Standard: Distribution<S> {
|
Standard: Distribution<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in a new issue