Skip to content

Lower Rustc version requirement to 1.9 for rand_core #413

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

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ matrix:
- cargo test --tests --no-default-features
- cargo test --package rand_core --no-default-features
- cargo test --features serde1,log
- rust: 1.13.0
install:
script:
# Ensure minimum rustc version for rand_core.
- cargo test --package rand_core --lib
- rust: stable
os: osx
install:
Expand Down
12 changes: 11 additions & 1 deletion rand_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-lang-nursery/rand?svg=true)](https://ci.appveyor.com/project/alexcrichton/rand)
[![Latest version](https://img.shields.io/crates/v/rand_core.svg)](https://crates.io/crates/rand_core)
[![Documentation](https://docs.rs/rand_core/badge.svg)](https://docs.rs/rand_core)
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.22+-yellow.svg)](https://github.com/rust-lang-nursery/rand#rust-version-requirements)
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.13+-yellow.svg)](https://github.com/rust-lang-nursery/rand#rust-version-requirements)

Core traits and error types of the [rand] library, plus tools for implementing
RNGs.
Expand Down Expand Up @@ -53,6 +53,16 @@ default features will also enable `std` support in `rand_core`.
The `serde1` feature can be used to derive `Serialize` and `Deserialize` for RNG
implementations that use the `BlockRng` or `BlockRng64` wrappers.

### Rust version requirements

`rand_core` works with a wide range of Rustc versions, with the oldest supported
version being **Rustc 1.13.0**. The optional `serde1` feature requires a higher
Rustc version, as it depends on the minimum version supported by Serde.

Travis CI always has a build with a pinned version of Rustc matching the oldest
supported Rust release. The current policy is that this can be updated in any
`rand_core` release if required, but the change must be noted in the changelog.


# License

Expand Down
33 changes: 20 additions & 13 deletions rand_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ pub struct Error {

impl Error {
/// Create a new instance, with specified kind and a message.
#[cfg(feature="std")]
pub fn new(kind: ErrorKind, msg: &'static str) -> Self {
#[cfg(feature="std")] {
Error { kind, msg, cause: None }
}
#[cfg(not(feature="std"))] {
Error { kind, msg }
}
Error { kind: kind, msg: msg, cause: None }
}
/// Create a new instance, with specified kind and a message.
#[cfg(not(feature="std"))]
pub fn new(kind: ErrorKind, msg: &'static str) -> Self {
Error { kind: kind, msg: msg }
}

/// Create a new instance, with specified kind, message, and a
Expand All @@ -119,7 +120,7 @@ impl Error {
pub fn with_cause<E>(kind: ErrorKind, msg: &'static str, cause: E) -> Self
where E: Into<Box<stdError + Send + Sync>>
{
Error { kind, msg, cause: Some(cause.into()) }
Error { kind: kind, msg: msg, cause: Some(cause.into()) }
}

/// Create a new instance, with specified kind, message, and a
Expand All @@ -128,7 +129,7 @@ impl Error {
/// In `no_std` mode the *cause* is ignored.
#[cfg(not(feature="std"))]
pub fn with_cause<E>(kind: ErrorKind, msg: &'static str, _cause: E) -> Self {
Error { kind, msg }
Error { kind: kind, msg: msg }
}

/// Take the cause, if any. This allows the embedded cause to be extracted.
Expand All @@ -139,18 +140,24 @@ impl Error {
}
}

#[cfg(feature="std")]
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[cfg(feature="std")] {
if let Some(ref cause) = self.cause {
return write!(f, "{} ({}); cause: {}",
self.msg, self.kind.description(), cause);
}
if let Some(ref cause) = self.cause {
return write!(f, "{} ({}); cause: {}",
self.msg, self.kind.description(), cause);
}
write!(f, "{} ({})", self.msg, self.kind.description())
}
}

#[cfg(not(feature="std"))]
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} ({})", self.msg, self.kind.description())
}
}

#[cfg(feature="std")]
impl stdError for Error {
fn description(&self) -> &str {
Expand Down
4 changes: 2 additions & 2 deletions rand_core/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<R: BlockRngCore> BlockRng<R> {
pub fn new(core: R) -> BlockRng<R>{
let results_empty = R::Results::default();
BlockRng {
core,
core: core,
index: results_empty.as_ref().len(),
results: results_empty,
}
Expand Down Expand Up @@ -400,7 +400,7 @@ impl<R: BlockRngCore> BlockRng64<R> {
pub fn new(core: R) -> BlockRng64<R>{
let results_empty = R::Results::default();
BlockRng64 {
core,
core: core,
index: results_empty.as_ref().len(),
half_used: false,
results: results_empty,
Expand Down