### Dynamically Dispatching an Iterator with Dynosaur Source: https://docs.rs/dynosaur/0.3.0/crates/dynosaur This example shows how to use the dynamically dispatched type generated by Dynosaur (e.g., `DynNext`) to iterate over items. It defines an `async fn` that accepts a mutable reference to the dynamic iterator type and consumes its elements using the `next().await` method. It also illustrates different ways to instantiate the dynamic iterator. ```rust async fn dyn_dispatch(iter: &mut DynNext<'_, i32>) { while let Some(item) = iter.next().await { println!("- {item}"); } } let v = [1, 2, 3]; // Assuming my_next_iter is an instance of a type implementing Next // dyn_dispatch(&mut DynNext::boxed(my_next_iter)).await; // dyn_dispatch(DynNext::from_mut(&mut my_next_iter)).await; ``` -------------------------------- ### Implement a Custom Iterator for Dynosaur Source: https://docs.rs/dynosaur/0.3.0/crates/dynosaur This code defines a concrete type `MyNextIter` that implements the `Next` trait, which is designed for dynamic dispatch with Dynosaur. The `next` method simulates asynchronous work and returns items from a vector. This serves as an example of a type that can be wrapped by Dynosaur's generated dynamic dispatch types. ```rust struct MyNextIter { v: Vec, i: usize, } impl Next for MyNextIter { type Item = T; async fn next(&mut self) -> Option { if self.i >= self.v.len() { return None; } do_some_async_work().await; let item = self.v[self.i]; self.i += 1; Some(item) } } async fn do_some_async_work() { // do something :) } ``` -------------------------------- ### Define Trait for Dynamic Dispatch with Dynosaur Source: https://docs.rs/dynosaur/0.3.0/crates/dynosaur This snippet demonstrates how to use the `dynosaur` proc macro to define a trait that can be dynamically dispatched. The `#[dynosaur::dynosaur(...)]` attribute transforms the `Next` trait, generating a dynamic dispatch type (e.g., `DynNext`). This is useful for traits involving `async fn` or `impl Trait` return types. ```rust #[dynosaur::dynosaur(DynNext = dyn(box) Next)] trait Next { type Item; async fn next(&mut self) -> Option; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.