Crates.io | dynosaur |
lib.rs | dynosaur |
version | |
source | src |
created_at | 2024-07-12 18:19:45.164111 |
updated_at | 2024-11-19 00:49:45.744191 |
description | Dynamic dispatch for return position impl traits and async in Rust |
homepage | |
repository | https://github.com/spastorino/dynosaur |
max_upload_size | |
id | 1300974 |
Cargo.toml error: | TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
dynosaur lets you use dynamic dispatch on traits with async fn
and
methods returning impl Trait
.
#[dynosaur::dynosaur(DynNext)]
trait Next {
type Item;
async fn next(&mut self) -> Self::Item;
}
The macro above generates a type called DynNext
which can be used like this:
async fn dyn_dispatch(iter: &mut DynNext<'_, i32>) {
while let Some(item) = iter.next().await {
println!("- {item}");
}
}
let a = [1, 2, 3];
dyn_dispatch(DynNext::from_mut(&mut a.into_iter())).await;
The general rule is that anywhere you would write dyn Trait
(which would
result in a compiler error), you instead write DynTrait
.
Methods returning impl Trait
box their return types when dispatched
dynamically, but not when dispatched statically.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.