Update the rand_derive code for Rand 0.5; add deprecation warning on use
diff --git a/Cargo.toml b/Cargo.toml
index ae39a57..c04a8b0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,7 +45,7 @@
[workspace]
-members = ["rand_core"]
+members = ["rand_core", "rand-derive"]
[dev-dependencies]
# This is for testing serde, unfortunately
diff --git a/rand-derive/Cargo.toml b/rand-derive/Cargo.toml
index 1a2dbe1..5b93018 100644
--- a/rand-derive/Cargo.toml
+++ b/rand-derive/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "rand_derive"
-version = "0.3.1"
+version = "0.5.0"
authors = ["The Rust Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
@@ -9,9 +9,12 @@
documentation = "https://docs.rs/rand_derive"
homepage = "https://github.com/rust-lang-nursery/rand"
description = """
-`#[derive(Rand)]` functionality for the `rand::Rand` trait.
+`#[derive(Rand)]` macro (deprecated).
"""
+[badges]
+maintenance = { status = "deprecated" }
+
[lib]
proc-macro = true
@@ -20,4 +23,4 @@
syn = "0.11"
[dev-dependencies]
-rand = { path = "..", version = "0.4" }
+rand = { version = "0.5" }
diff --git a/rand-derive/README.md b/rand-derive/README.md
index b645a46..53bcaca 100644
--- a/rand-derive/README.md
+++ b/rand-derive/README.md
@@ -1,19 +1,21 @@
rand_derive
====
-`#[derive(Rand)]` functionality for the `rand::Rand` trait.
+`#[derive(Rand)]` functionality enabling sampling of random instances.
-**This module is deprecated as of rand 0.5**, due in part to breaking changes
-in rand and in part to lack of use. Code is preserved because in theory it
-should be straightforward to modify for use with rand's new distribution code.
+**This crate is deprecated as of rand 0.5** since the `Rand` trait has been
+deprecated and since it appears to have very little use.
+
+This crate has been updated to work with Rand 0.5, however note that it now
+implements `Distribution<Self> for Standard` instead of `Rand`.
## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
-rand = "0.4"
-rand_macros = "0.2"
+rand = "0.5"
+rand_derive = "0.5"
```
and this to your crate root:
@@ -21,7 +23,7 @@
```rust
extern crate rand;
#[macro_use]
-extern crate rand_macros;
+extern crate rand_derive;
```
## Examples
diff --git a/rand-derive/src/lib.rs b/rand-derive/src/lib.rs
index 80c803a..111805b 100644
--- a/rand-derive/src/lib.rs
+++ b/rand-derive/src/lib.rs
@@ -1,4 +1,6 @@
-//! Support for `#[derive(Rand)]`
+//! Support for `#[derive(Rand)]` (deprecated)
+//!
+//! **Both the `Rand` trait and the `derive(Rand)` macro are deprecated.**
//!
//! # Examples
//!
@@ -18,6 +20,8 @@
//! }
//! ```
+#![deprecated(since="0.5.0", note="this crate is deprecated without replacement")]
+
extern crate proc_macro;
#[macro_use]
extern crate quote;
@@ -106,9 +110,13 @@
};
quote! {
- impl #impl_generics ::rand::Rand for #name #ty_generics #where_clause {
+ impl #impl_generics ::rand::distributions::Distribution<#name>
+ for ::rand::distributions::Standard
+ #ty_generics
+ #where_clause
+ {
#[inline]
- fn rand<__R: ::rand::Rng>(__rng: &mut __R) -> Self {
+ fn sample<__R: ::rand::Rng + ?Sized>(&self, __rng: &mut __R) -> #name {
#rand
}
}