[−][src]Attribute Macro completion::completion
#[completion]
An attribute macro to generate completion async fn
s. These async functions evaluate to a
CompletionFuture
, and you can .await
other CompletionFuture
s inside of them.
Requires the macro
feature.
Examples
use completion::{completion, completion_async}; #[completion] async fn async_completion() -> i32 { let fut = async { 3 }; let completion_fut = completion_async! { 5 }; fut.await + completion_fut.await }
This macro needs to know a path to this crate in order to work. By default it uses
::completion
, but you can change it using the crate
option:
mod path { pub mod to { pub extern crate completion as completion_crate; } } use path::to::completion_crate::completion; #[completion(crate = path::to::completion_crate)] async fn async_completion(x: &i32) -> i32 { *x }
You can return a boxed completion future from the function by using the box
option. For
example this can be used to implement async traits:
use completion::completion; trait MyTrait { #[completion(box)] async fn run(&self); } struct Item; impl MyTrait for Item { #[completion(box)] async fn run(&self) { println!("Hello!"); } }
By default the box
option will require the futures to implement Send
. If you don't want
this, you can pass in the ?Send
option:
use completion::completion; trait MyTrait { #[completion(box(?Send))] async fn run(&self); }
That will allow you to hold !Send
types across await points in the future, but will only
allow it to be executed on a single-threaded executor.