pub trait IntoWorldResult: Sized {
type World: World;
type Error;
// Required method
fn into_world_result(self) -> Result<Self::World, Self::Error>;
}Available on crate feature
macros only.Expand description
Return-type polymorphism over fallibility for a #[world(init)] attribute
of a #[derive(World)] macro.
It allows to accept both fallible (returning Result) and infallible
functions as an attribute’s argument, by automatically wrapping infallible
functions in a Result<World, Infallible>.
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()
.await
.into_world_result() // maybe wraps into `Result<_, Infallible>`
.map_err(Into::into)
}
}Required Associated Types§
Sourcetype Error
type Error
Error returned by this World constructor.
Set to Infallible in case construction is infallible.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.