Skip to content

Commit

Permalink
Improves the docs on derive
Browse files Browse the repository at this point in the history
So I've done a bit of work to improve the derive docs.

I do think another improvement may be to copy the style
done in the tokio docs and for some simple examples
show how the generated code looks. However, I think fake would benefit
less from this compared to tokio (how a runtime is setup for an async
application is important to more people). So it may just add unnecessary
noise to the docs.

I guess an issue should be made for the tuple enums - or maybe there's
another way to do it I need to experiment/read-macro-code more
  • Loading branch information
xd009642 committed Aug 15, 2023
1 parent 5862a6c commit 000e7c4
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions fake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,15 @@ pub mod faker;
/// Locales used for custom [`Dummy`] implementations within [`faker`] module.
pub mod locales;

/// Derive macro generating an impl of the trait [`Dummy`].
/// Derive macro generating an impl of the trait [`Dummy`]. This works for both structs and enums.
///
/// For any fields in the type the `faker` key in `dummy` attribute could be used provided the field
/// implements [`Fake`].
///
/// # Examples
///
/// A simple example for deriving [`Dummy`] on a struct:
///
/// ```
/// use fake::{Dummy, Fake, Faker};
/// use fake::faker::name::en::Name;
Expand All @@ -291,8 +296,26 @@ pub mod locales;
/// let f: Foo = Faker.fake();
/// ```
///
/// `faker` key in `dummy` attribute could be used on any type that implements
/// [`Fake`].
/// A simple example for deriving [`Dummy`] on an enum. Unfortunately, the `faker` key cannot yet
/// be used on tuple enum variants. However, it can be used on fields within struct enum variants.
///
/// ```
/// use fake::{Dummy, Fake, Faker};
/// use fake::faker::name::en::Name;
///
/// #[derive(Dummy)]
/// pub struct Bar {
/// Simple,
/// Tuple(i32),
/// Structure {
/// #[dummy(faker = "1000..2000")]
/// i: usize,
/// j: String,
/// }
/// }
///
/// let f: Foo = Faker.fake();
/// ```
#[cfg(feature = "derive")]
pub use dummy::Dummy;

Expand Down

0 comments on commit 000e7c4

Please sign in to comment.