Skip to content

Commit

Permalink
Merge pull request #143 from saiintbrisson/master
Browse files Browse the repository at this point in the history
feat: expose rng trait hidden
  • Loading branch information
cksac authored Aug 17, 2023
2 parents 284f168 + e3bc7dc commit 700933f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions dummy_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn derive_dummy(input: TokenStream) -> TokenStream {
ast::Style::Unit => {
let impl_dummy = quote! {
impl ::fake::Dummy<::fake::Faker> for #receiver_name {
fn dummy_with_rng<R: ::rand::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
fn dummy_with_rng<R: ::fake::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
#receiver_name
}
}
Expand All @@ -74,7 +74,7 @@ pub fn derive_dummy(input: TokenStream) -> TokenStream {

let impl_dummy = quote! {
impl ::fake::Dummy<::fake::Faker> for #receiver_name {
fn dummy_with_rng<R: ::rand::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
fn dummy_with_rng<R: ::fake::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
#receiver_name(#(#tuple_fields),*)
}
}
Expand All @@ -99,7 +99,7 @@ pub fn derive_dummy(input: TokenStream) -> TokenStream {

let impl_dummy = quote! {
impl ::fake::Dummy<::fake::Faker> for #receiver_name {
fn dummy_with_rng<R: ::rand::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
fn dummy_with_rng<R: ::fake::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
#(#let_statements)*
#receiver_name {
#(#struct_fields),*
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn derive_dummy(input: TokenStream) -> TokenStream {

let impl_dummy = quote! {
impl ::fake::Dummy<::fake::Faker> for #receiver_name {
fn dummy_with_rng<R: ::rand::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
fn dummy_with_rng<R: ::fake::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
match rng.gen_range(0..#variant_count) {
#(#match_statements)*
_ => {
Expand All @@ -186,7 +186,7 @@ pub fn derive_dummy(input: TokenStream) -> TokenStream {
} else {
let impl_dummy = quote! {
impl ::fake::Dummy<::fake::Faker> for #receiver_name {
fn dummy_with_rng<R: ::rand::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
fn dummy_with_rng<R: ::fake::Rng + ?Sized>(_: &::fake::Faker, rng: &mut R) -> Self {
panic!("can not create an empty enum")
}
}
Expand Down
5 changes: 3 additions & 2 deletions fake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
//! let result: Option<i64> = Faker.fake_with_rng(&mut rng);
//! println!("Always Some: {}", result.unwrap());
//! ```
use rand::Rng;
#[doc(hidden)]
pub use rand::Rng;

/// Generate default fake value for given type using [`Fake`].
///
Expand Down Expand Up @@ -286,7 +287,7 @@ pub mod locales;

/// Derive macro generating an impl of the trait [`Dummy`]. This works for both structs and enums.
///
/// # Attributes
/// # Attributes
///
/// For any fields in the type there are a number of keys that can be used to control the code generation.
/// All of these go within the dummy attribute.
Expand Down

0 comments on commit 700933f

Please sign in to comment.