Trait cucumber::codegen::ToWorldFuture
source · [−]pub trait ToWorldFuture {
type Future: Future;
fn to_world_future(&self) -> Self::Future;
}
Available on crate feature
macros
only.Expand description
Return-type polymorphism over async
ness for a #[world(init)]
attribute
of a #[derive(World)]
macro.
It allows to accept both sync and async
functions as an attribute’s
argument, by automatically wrapping sync functions in a [future::Ready
].
#[async_trait(?Send)]
impl cucumber::World for World {
type Error = anyhow::Error;
async fn new() -> Result<Self, Self::Error> {
use cucumber::codegen::{
IntoWorldResult as _, ToWorldFuture as _,
};
fn as_fn_ptr<T>(v: fn() -> T) -> fn() -> T {
v
}
// `#[world(init)]`'s value
// ⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
(&as_fn_ptr(<Self as Default>::default))
.to_world_future() // maybe wraps into `future::Ready`
.await
.into_world_result()
.map_err(Into::into)
}
}
Required Associated Types
Required Methods
sourcefn to_world_future(&self) -> Self::Future
fn to_world_future(&self) -> Self::Future
Resolves this Future
for constructing a newWorld
using
autoderef-based specialization.