pub trait FromFuture<'a, T, F>where
T: 'a,
F: Future<Output = T> + 'a,{
// Required method
fn from_future(f: F) -> Self;
}Expand description
A trait for constructing FutureForm-specific types from raw futures.
This abstracts over the wrapping operation, allowing generic code to construct the appropriate future type without knowing the concrete form.
Typically you’ll use FutureForm::from_future instead of calling this directly.
§Example
use future_form::{FutureForm, Sendable, Local};
use futures::future::{BoxFuture, LocalBoxFuture};
trait Counter<K: FutureForm> {
fn next(&self) -> K::Future<'_, u32>;
}
struct Memory { val: u32 }
impl Counter<Sendable> for Memory {
fn next(&self) -> BoxFuture<'_, u32> {
let val = self.val;
Sendable::from_future(async move { val + 1 })
}
}
impl Counter<Local> for Memory {
fn next(&self) -> LocalBoxFuture<'_, u32> {
let val = self.val;
Local::from_future(async move { val + 1 })
}
}Required Methods§
Sourcefn from_future(f: F) -> Self
fn from_future(f: F) -> Self
Create this type from a future.
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.