Skip to content

Commit

Permalink
Add docs for using with trait_variant
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Oct 1, 2024
1 parent 5aa8400 commit 7ebb826
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ resolver = "2"

[workspace.dependencies]
tokio = { version = "1.40.0", features = ["macros", "rt"] }
trait-variant = "0.1"
2 changes: 1 addition & 1 deletion dynosaur/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dynosaur_derive = { version = "0.1", path = "../dynosaur_derive" }
[dev-dependencies]
tokio = { workspace = true }
ui_test = "0.24"
trait-variant = "0.1"
trait-variant = { workspace = true }

[[example]]
name = "next"
Expand Down
1 change: 1 addition & 0 deletions dynosaur_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ syn = { version = "2.0", features = ["full", "visit-mut"] }

[dev-dependencies]
tokio = { workspace = true }
trait-variant = { workspace = true }
21 changes: 21 additions & 0 deletions dynosaur_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ impl Parse for Attrs {
/// When using the `Dyn` struct created by this macro, such conversions must be
/// done explicitly with the provided constructors.
///
/// ## Use with `trait_variant`
///
/// You can use dynosaur with the trait_variant macro like this. The
/// trait_variant attribute must go first.
///
/// ```rust
/// # pub mod dynosaur { pub use dynosaur_derive::dynosaur; }
/// #[trait_variant::make(SendNext: Send)]
/// #[dynosaur::dynosaur(DynNext = dyn Next)]
/// #[dynosaur::dynosaur(DynSendNext = dyn SendNext)]
/// trait Next {
/// type Item;
/// async fn next(&mut self) -> Option<Self::Item>;
/// }
/// # // This is necessary to prevent weird scoping errors in the doctets:
/// # fn main() {}
/// ```
///
/// The `DynNext = dyn Next` is a more explicit form of the macro invocation
/// that allows you to select a particular trait.
///
/// ## Performance
///
/// In addition to the normal overhead of dynamic dispatch, calling `async` and
Expand Down

0 comments on commit 7ebb826

Please sign in to comment.