pub enum Sendable {}Expand description
Abstraction over Send futures.
Use this when your async code needs to work with multi-threaded runtimes
like tokio or async-std that require futures to be Send.
§Example
use future_form::{FutureForm, Sendable};
use futures::future::BoxFuture;
trait Cache<K: FutureForm> {
fn fetch<'a>(&'a self, key: &'a str) -> K::Future<'a, Option<String>>;
}
struct RedisCache;
// Implement for Send futures - can be used with tokio
impl Cache<Sendable> for RedisCache {
fn fetch<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Option<String>> {
Sendable::from_future(async move {
// Simulate fetching from Redis
Some(format!("value-{}", key))
})
}
}Trait Implementations§
Source§impl FutureForm for Sendable
impl FutureForm for Sendable
Source§type Future<'a, T: 'a> = Pin<Box<dyn Future<Output = T> + Send + 'a>>
type Future<'a, T: 'a> = Pin<Box<dyn Future<Output = T> + Send + 'a>>
An abstraction over future types. Read more
Source§fn ready<'a, T>(value: T) -> Self::Future<'a, T>
fn ready<'a, T>(value: T) -> Self::Future<'a, T>
Create this form’s future type from an already-computed value. Read more
Source§fn from_future<'a, T, F>(f: F) -> Self::Future<'a, T>
fn from_future<'a, T, F>(f: F) -> Self::Future<'a, T>
Create this form’s future type from a raw future. Read more
impl Copy for Sendable
Auto Trait Implementations§
impl Freeze for Sendable
impl RefUnwindSafe for Sendable
impl Send for Sendable
impl Sync for Sendable
impl Unpin for Sendable
impl UnsafeUnpin for Sendable
impl UnwindSafe for Sendable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more