RequestExt

Trait RequestExt 

Source
pub trait RequestExt<'w, 's> {
    // Required method
    fn request<'a, P: ProvideOnce>(
        &'a mut self,
        request: P::Request,
        provider: P,
    ) -> Series<'w, 's, 'a, P::Response, P::Streams>
       where P::Request: 'static + Send + Sync,
             P::Response: 'static + Send + Sync,
             P::Streams: StreamPack;

    // Provided methods
    fn provide<'a, T: 'static + Send + Sync>(
        &'a mut self,
        value: T,
    ) -> Series<'w, 's, 'a, T, ()> { ... }
    fn serve<'a, T: 'static + Send + Sync + Future>(
        &'a mut self,
        future: T,
    ) -> Series<'w, 's, 'a, T::Output, ()>
       where T::Output: 'static + Send + Sync { ... }
}
Expand description

Extensions for creating a series of execution by making a request to a provider or serving a value. This is implemented for Commands.

Required Methods§

Source

fn request<'a, P: ProvideOnce>( &'a mut self, request: P::Request, provider: P, ) -> Series<'w, 's, 'a, P::Response, P::Streams>
where P::Request: 'static + Send + Sync, P::Response: 'static + Send + Sync, P::Streams: StreamPack,

Call this on Commands to begin creating a series.

A series is a one-time chain of requests where the output of each request feeds into the input of the next. You should end the series by taking the response, detaching the series, or using one of the other terminating operations mentioned in the chart. You can do a single request (instead of a chain) by just taking the response immediately after the first request.

use crossflow::{prelude::*, testing::*};
let mut context = TestingContext::minimal_plugins();
let mut promise = context.command(|commands| {
    let service = commands.spawn_service(spawn_test_entities);
    commands.request(5, service).take().response
});

context.run_while_pending(&mut promise);
assert!(promise.peek().is_available());

Provided Methods§

Source

fn provide<'a, T: 'static + Send + Sync>( &'a mut self, value: T, ) -> Series<'w, 's, 'a, T, ()>

Call this on Commands to begin building a series from a value without calling any provider.

Source

fn serve<'a, T: 'static + Send + Sync + Future>( &'a mut self, future: T, ) -> Series<'w, 's, 'a, T::Output, ()>
where T::Output: 'static + Send + Sync,

Call this on Commands to begin building a series from a Future whose Future::Output will be the item provided to the target.

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.

Implementors§

Source§

impl<'w, 's> RequestExt<'w, 's> for Commands<'w, 's>