Skip to content

Commit

Permalink
Add macro docs, move details there
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Dec 21, 2023
1 parent 2e82d4f commit 865bd5f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ trait LocalIntFactory {
async fn make(&self) -> i32;
// ..or..
fn stream(&self) -> impl Iterator<Item = i32>;
fn call(&self) -> u32;
}
```

Which creates a new `IntFactory: Send` trait and additionally bounds `IntFactory::make(): Send` and `IntFactory::stream(): Send`. Ordinary methods are not affected.
Which creates a new `IntFactory: Send` trait and additionally bounds `IntFactory::make(): Send` and `IntFactory::stream(): Send`. Implementers of the trait can choose to implement the variant instead of the original trait.

Implementers of the trait can choose to implement the variant instead of the original trait. The macro creates a blanket impl which ensures that any type which implements the variant also implements the original trait.
For more details, see the docs for [`trait_variant::make`].

[`trait_variant::make`]: https://docs.rs/trait-variant/latest/trait_variant/attr.make.html

#### License and usage notes

Expand Down
27 changes: 27 additions & 0 deletions trait-variant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@

mod variant;

/// Creates a specialized version of a base trait that adds bounds to `async
/// fn` and/or `-> impl Trait` return types.
///
/// ```
/// #[trait_variant::make(IntFactory: Send)]
/// trait LocalIntFactory {
/// async fn make(&self) -> i32;
/// fn stream(&self) -> impl Iterator<Item = i32>;
/// fn call(&self) -> u32;
/// }
/// ```
///
/// The above example causes a second trait called `IntFactory` to be created:
///
/// ```
/// trait IntFactory: Send {
/// fn make(&self) -> impl Future<Output = i32> + Send;
/// fn stream(&self) -> impl Iterator<Item = i32> + Send;
/// fn call(&self) -> u32;
/// }
/// ```
///
/// Note that ordinary methods such as `call` are not affected.
///
/// Implementers of the trait can choose to implement the variant instead of the
/// original trait. The macro creates a blanket impl which ensures that any type
/// which implements the variant also implements the original trait.
#[proc_macro_attribute]
pub fn make(
attr: proc_macro::TokenStream,
Expand Down

0 comments on commit 865bd5f

Please sign in to comment.