Skip to main content

FileStorage

Struct FileStorage 

Source
pub struct FileStorage<Args, A: Adapter> { /* private fields */ }
Expand description

A backend that persists to a file using json encoding

Warning: This backend is not optimized for high-throughput scenarios and is best suited for development, testing, or low-volume workloads.

§Example

Creates a temporary JSON storage backend

let mut backend: JsonStorage<u32> = JsonStorage::new_temp().unwrap();

§Features

FeatureStatusDescription
Backend✅Basic Backend functionality
TaskSink✅Ability to push new tasks
Serialization✅ ❗Serialization support for arguments. Only accepts json
Web Interface⚠️Expose a web interface for monitoring tasks
FetchById⚠️Allow fetching a task by its ID
RegisterWorker❌Allow registering a worker with the backend
[PipeExt]✅Allow other backends to pipe to this backend
BackendFactory✅Share the same storage across multiple workers via SharedJsonStore
Workflow✅Flexible enough to support workflows
WaitForCompletion✅Wait for tasks to complete without blocking
ResumeById⚠️Resume a task by its ID
ResumeAbandoned⚠️Resume abandoned tasks
ListWorkers❌List all workers registered with the backend
ListTasks⚠️List all tasks in the backend

Key: ✅ : Supported | ⚠️ : Not implemented | ❌ : Not Supported | ❗ Limited support

Tests:
§Backend
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    async fn task(task: u32, worker: WorkerContext) {
        // Do some work 
    }
    let worker = WorkerBuilder::new("backend-test")
        .backend(backend)
        .build(task);
    let _ = worker.stream().take(1).collect::<Vec<_>>().await;
}
§TaskSink
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    backend.push(42).await.unwrap();

    async fn task(task: u32, worker: WorkerContext) {
        worker.stop().unwrap();
    }
    let worker = WorkerBuilder::new("task-sink-test")
        .backend(backend)
        .build(task);
    worker.run().await.unwrap();
}
§Workflow
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    backend.push(42).await.unwrap();

    async fn task1(task: u32, worker: WorkerContext) -> u32 {
        task + 99 
    }
    async fn task2(task: u32, worker: WorkerContext) -> u32 {
        task + 1 
    }
    async fn task3(task: u32, worker: WorkerContext) {
        assert_eq!(task, 142);
        worker.stop().unwrap();
    }
    let workflow = SteppedFlow::new("test-workflow")
       .and_then(task1)
       .and_then(task2)
       .and_then(task3);
    let worker = WorkerBuilder::new("workflow-test")
        .backend(backend)
        .build(workflow);
    worker.run().await.unwrap();
}
§WaitForCompletion
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    fn assert_wait_for_completion<B: WaitForCompletion<u32> + Backend>(backend: B) {};
    assert_wait_for_completion(backend);
}

Implementations§

Source§

impl<A: Adapter, Args> FileStorage<Args, A>

Source

pub fn new(path: impl AsRef<Path>) -> Result<Self, FileStorageError<A>>
where A: Default,

Creates a new FileStorage instance using the specified file path.

Source

pub fn new_temp() -> Result<Self, FileStorageError<A>>
where A: Default,

Creates a new temporary FileStorage instance.

Source

pub fn set_result( &mut self, line_id: usize, result: Value, ) -> Result<(), FileStorageError<A>>

Attach a result to the entry identified by line_id.

Source

pub fn flush(&mut self) -> Result<(), FileStorageError<A>>

Persist all pending changes under an exclusive file lock.

Source

pub fn tick(&mut self) -> Result<(), FileStorageError<A>>

Drive periodic syncing. Call this from your timer loop.

Trait Implementations§

Source§

impl<Args, Res, A> Acknowledge<Res> for FileStorage<Args, A>
where Args: Send + 'static + Debug, Res: Serialize, A: Adapter + Clone,

Source§

type Error = FileStorageError<A>

The error type returned by the acknowledgment process
Source§

type Future = Ready<Result<(), <FileStorage<Args, A> as Acknowledge<Res>>::Error>>

The future returned by the ack method
Source§

fn ack( &mut self, res: &Result<Res, BoxDynError>, ctx: &ExecutionContext, ) -> Self::Future

Acknowledge the result of a task processing
Source§

impl<Args, A> Backend for FileStorage<Args, A>
where Args: 'static + Send + Serialize + for<'de> Deserialize<'de> + Unpin, A: Adapter + Unpin, A::Error: Error + Send + Sync + 'static,

Source§

type Task = Task<Value>

The type of task the backend emits.
Source§

type Error = FileStorageError<A>

The error type returned by backend operations
Source§

fn poll_ready( &mut self, cx: &mut Context<'_>, _: &WorkerContext, ) -> Poll<Result<(), Self::Error>>

Polls whether the backend is ready for the worker to request more work. Read more
Source§

fn poll_next( &mut self, cx: &mut Context<'_>, _: &WorkerContext, ) -> Poll<Option<Result<Self::Task, Self::Error>>>

Polls the backend for the next available task for this worker. Read more
Source§

fn poll_close( &mut self, _: &mut Context<'_>, _: &WorkerContext, ) -> Poll<Result<(), Self::Error>>

Flushes/releases any resources the backend holds (pending acks, open subscriptions, connections) before the worker fully shuts down.
Source§

impl<Args, A> BackendConfig for FileStorage<Args, A>
where Args: 'static + Send + Serialize + for<'de> Deserialize<'de> + Unpin, A: Adapter + Unpin + Clone, A::Error: Error + Send + Sync + 'static,

Source§

type Args = Args

The type of argument this backend emits
Source§

type Id = RandomId

The internal type of this Backend’s TaskId
Source§

type Kind = Durable

This defines the kind of Backend
Source§

type Config = PathBuf

The config for the backend
Source§

type Layer = AcknowledgeLayer<FileStorage<Args, A>>

The type representing backend middleware layer.
Source§

fn middleware(&mut self, _: &mut WorkerContext) -> Self::Layer

Returns the backend’s middleware layer.
Source§

fn config(&self) -> &Self::Config

Returns the config associated with the backend.
Source§

impl<Args, A> Clone for FileStorage<Args, A>
where A: Adapter + Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Args: Debug, A: Debug + Adapter> Debug for FileStorage<Args, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: Adapter + Unpin, Args: Unpin> Sink<Task<Value>> for FileStorage<Args, A>

Source§

type Error = FileStorageError<A>

The type of value produced by the sink when an error occurs.
Source§

fn poll_ready( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
Source§

fn start_send( self: Pin<&mut Self>, item: Task<Value>, ) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
Source§

fn poll_flush( self: Pin<&mut Self>, _: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
Source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
Source§

impl<A: Adapter + Unpin, Args: Unpin> Stream for FileStorage<Args, A>

Source§

type Item = Result<(usize, RawTask), FileStorageError<A>>

Values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more
Source§

impl<Args, A> TryNewBackend for FileStorage<Args, A>
where A: Adapter + Default + Unpin + Sync + Clone, A::Error: Error + Send + Sync + 'static, Args: Serialize + DeserializeOwned + 'static + Send + Sync + Unpin,

Source§

type Backend = FileStorage<Args, A>

The final backend after decoration Read more
Source§

fn try_new(config: Self::Config) -> Result<Self::Backend, Self::Error>

Attempt to construct a new backend instance from its configuration.
Source§

impl<Args, A, O> WaitForCompletion<O> for FileStorage<Args, A>
where O: Send + DeserializeOwned + 'static + Unpin + Serialize, A: Adapter + Unpin + Sync + Clone, A::Error: Error + Send + Sync + 'static, Args: Serialize + DeserializeOwned + 'static + Send + Sync + Unpin,

Source§

type ResultStream = Pin<Box<dyn Stream<Item = Result<TaskResult<O>, FileStorageError<A>>> + Send>>

The result stream type yielding task results
Source§

fn wait_for( &mut self, task_ids: impl IntoIterator<Item = TaskId>, ) -> Self::ResultStream

Wait for multiple tasks to complete, yielding results as they become available
Source§

async fn check_status( &mut self, task_ids: impl IntoIterator<Item = TaskId> + Send, ) -> Result<Vec<TaskResult<O>>, Self::Error>

Check current status of tasks without waiting
Source§

fn wait_for_single(&mut self, task_id: TaskId) -> Self::ResultStream

Wait for a single task to complete, yielding its result
Source§

impl<Args, A> WireFormatBackend for FileStorage<Args, A>
where Args: 'static + Send + Serialize + for<'de> Deserialize<'de> + Unpin, A: Adapter + Unpin, A::Error: Error + Send + Sync + 'static,

Source§

type Codec = JsonCodec<Value>

The codec used to encode and decode tasks.
Source§

type Compact = Value

The compact representation of task arguments.
Source§

fn codec(&self) -> &Self::Codec

Returns a reference to the codec used by the backend.

Auto Trait Implementations§

§

impl<Args, A> Freeze for FileStorage<Args, A>
where A: Freeze, PhantomData<Args>: Freeze,

§

impl<Args, A> RefUnwindSafe for FileStorage<Args, A>

§

impl<Args, A> Send for FileStorage<Args, A>
where PhantomData<Args>: Send,

§

impl<Args, A> Sync for FileStorage<Args, A>
where A: Sync, PhantomData<Args>: Sync,

§

impl<Args, A> Unpin for FileStorage<Args, A>
where A: Unpin, PhantomData<Args>: Unpin,

§

impl<Args, A> UnsafeUnpin for FileStorage<Args, A>

§

impl<Args, A> UnwindSafe for FileStorage<Args, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<B> BackendExt for B
where B: Backend,

Source§

fn poll_next_args( &mut self, cx: &mut Context<'_>, worker: &WorkerContext, ) -> Poll<Option<Result<Task<Self::Args>, PollNextArgsError<Self>>>>
where Self: Sized + BackendConfig + WireFormatBackend + Backend<Task = Task<Self::Compact>>, Self::Codec: Codec<Self::Args, Compact = Self::Compact>, <Self::Codec as Codec<Self::Args>>::Error: Error + Send + Sync + 'static,

A convenience method for calling poll_next and decoding the Args in one step, returning a Task<Self::Args, ..> instead of Task<Self::Compact, ..>.
Source§

fn pipe_to<Dst>(self, backend: Dst) -> Pipe<Dst, Self>
where Self: Sized,

Pipes every task polled from this backend into sink Read more
Source§

fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
where Self: Sized, F: Fn(&Self::Error),

Attaches a callback F to be run on each error produced while polling the backend.
Source§

fn map_err<F, E2>(self, f: F) -> MapErr<Self, F>
where Self: Sized, F: Fn(Self::Error) -> E2,

Maps errors produced by the backend from Self::Error into E2, useful for heterogeneous composed backends.
Source§

fn with_codec<NewCodec>(self, codec: NewCodec) -> WithCodec<Self, NewCodec>
where Self: Sized + BackendConfig, NewCodec: Codec<Self::Args>,

Swaps out the backend’s serialization codec entirely (JSON, MessagePack, Protobuf, …) without touching storage logic.
Source§

fn poll_with_stream<S>(self, stream: S) -> PollWith<Self, StreamStrategy<S>>
where Self: Sized, S: Stream + Unpin + Send + 'static,

Wake the worker when a stream receives a new item
Source§

fn poll_with_interval( self, duration: Duration, ) -> PollWith<Self, IntervalStrategy>
where Self: Sized,

Available on crate feature sleep only.
Wake the worker periodically
Source§

fn poll_with_backoff( self, interval: Duration, config: BackoffConfig, ) -> PollWith<Self, BackoffStrategy>
where Self: Sized,

Available on crate feature sleep only.
Wake the worker periodically with a backoff
Source§

fn poll_with_strategy<S>(self, strategy: S) -> PollWith<Self, S>
where Self: Sized, S: PollStrategy,

Wake the worker with a custom strategy
Source§

fn before_start<F, Fut>(self, f: F) -> BeforeStart<Self, Self::Error>
where Self: Sized, F: Fn(&mut Self) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), Self::Error>> + Send + 'static,

Runs an async callback once, before the backend’s first poll_ready is delegated.
Source§

fn before_stop<F, Fut>(self, f: F) -> BeforeStop<Self, Self::Error>
where Self: Sized, F: Fn(&mut Self) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), Self::Error>> + Send + 'static,

Runs an async callback once, before the backend’s poll_close is called.
Source§

fn after_start<F, Fut>(self, f: F) -> AfterStart<Self, Self::Error>
where Self: Sized, F: for<'c> Fn(&mut Self) -> Fut + for<'c> Send + for<'c> Sync + 'static, Fut: Future<Output = Result<(), Self::Error>> + Send + 'static,

Runs an async callback once, after the backend’s first poll_ready is successful.
Source§

fn after_stop<F, Fut>(self, f: F) -> AfterStop<Self, Self::Error>
where Self: Sized, F: Fn(&mut Self) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), Self::Error>> + Send + 'static,

Runs an async callback once, after the worker has stopped and backend has cleaned up.
Source§

fn interleave<S>(self, stream: S) -> Interleave<Self, S>
where Self: Sized, S: Stream<Item = Result<Self::Task, Self::Error>> + Unpin,

Interleaves the external stream with the backend.
Source§

fn wake_on_push(self) -> WakeOnPush<Self>
where Self: Sized,

Wakes the worker when a new item is pushed
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<B, Args, Err, S> PipeExt<B, Args> for S
where B: Backend + Unpin + Send + 'static, S: Stream<Item = Result<Args, Err>> + Send + Unpin + 'static, Err: Into<Box<dyn Error + Send + Sync>> + Send + Sync + 'static, Args: 'static,

Source§

fn pipe_to( self, backend: B, ) -> Pipe<B, Pin<Box<dyn Stream<Item = Result<Args, PipeError>> + Send>>>

Pipe the current stream into the provided sink backend.
Source§

impl<T, Item> SinkExt<Item> for T
where T: Sink<Item> + ?Sized,

Source§

fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
where F: FnMut(U) -> Fut, Fut: Future<Output = Result<Item, E>>, E: From<Self::Error>, Self: Sized,

Composes a function in front of the sink. Read more
Source§

fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
where F: FnMut(U) -> St, St: Stream<Item = Result<Item, Self::Error>>, Self: Sized,

Composes a function in front of the sink. Read more
Source§

fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
where F: FnOnce(Self::Error) -> E, Self: Sized,

Transforms the error returned by the sink.
Source§

fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
where Self: Sized, Self::Error: Into<E>,

Map this sink’s error to a different error type using the Into trait. Read more
Source§

fn buffer(self, capacity: usize) -> Buffer<Self, Item>
where Self: Sized,

Available on crate feature alloc only.
Adds a fixed-size buffer to the current sink. Read more
Source§

fn close(&mut self) -> Close<'_, Self, Item> ⓘ
where Self: Unpin,

Close the sink.
Source§

fn fanout<Si>(self, other: Si) -> Fanout<Self, Si>
where Self: Sized, Item: Clone, Si: Sink<Item, Error = Self::Error>,

Fanout items to multiple sinks. Read more
Source§

fn flush(&mut self) -> Flush<'_, Self, Item> ⓘ
where Self: Unpin,

Flush the sink, processing all pending items. Read more
Source§

fn send(&mut self, item: Item) -> Send<'_, Self, Item> ⓘ
where Self: Unpin,

A future that completes after the given item has been fully processed into the sink, including flushing. Read more
Source§

fn feed(&mut self, item: Item) -> Feed<'_, Self, Item> ⓘ
where Self: Unpin,

A future that completes after the given item has been received by the sink. Read more
Source§

fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St> ⓘ
where St: TryStream<Ok = Item, Error = Self::Error> + Stream + Unpin + ?Sized, Self: Unpin,

A future that completes after the given stream has been fully processed into the sink, including flushing. Read more
Source§

fn left_sink<Si2>(self) -> Either<Self, Si2> ⓘ
where Si2: Sink<Item, Error = Self::Error>, Self: Sized,

Wrap this sink in an Either sink, making it the left-hand variant of that Either. Read more
Source§

fn right_sink<Si1>(self) -> Either<Si1, Self> ⓘ
where Si1: Sink<Item, Error = Self::Error>, Self: Sized,

Wrap this stream in an Either stream, making it the right-hand variant of that Either. Read more
Source§

fn poll_ready_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_ready on Unpin sink types.
Source§

fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>
where Self: Unpin,

A convenience method for calling Sink::start_send on Unpin sink types.
Source§

fn poll_flush_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_flush on Unpin sink types.
Source§

fn poll_close_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_close on Unpin sink types.
Source§

impl<T> StreamExt for T
where T: Stream + ?Sized,

Source§

fn next(&mut self) -> Next<'_, Self> ⓘ
where Self: Unpin,

Creates a future that resolves to the next item in the stream. Read more
Source§

fn into_future(self) -> StreamFuture<Self> ⓘ
where Self: Sized + Unpin,

Converts this stream into a future of (next_item, tail_of_stream). If the stream terminates, then the next item is None. Read more
Source§

fn map<T, F>(self, f: F) -> Map<Self, F>
where F: FnMut(Self::Item) -> T, Self: Sized,

Maps this stream’s items to a different type, returning a new stream of the resulting type. Read more
Source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Creates a stream which gives the current iteration count as well as the next value. Read more
Source§

fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
where F: FnMut(&Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,

Filters the values produced by this stream according to the provided asynchronous predicate. Read more
Source§

fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
where F: FnMut(Self::Item) -> Fut, Fut: Future<Output = Option<T>>, Self: Sized,

Filters the values produced by this stream while simultaneously mapping them to a different type according to the provided asynchronous closure. Read more
Source§

fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
where F: FnMut(Self::Item) -> Fut, Fut: Future, Self: Sized,

Computes from this stream’s items new items of a different type using an asynchronous closure. Read more
Source§

fn collect<C>(self) -> Collect<Self, C> ⓘ
where C: Default + Extend<Self::Item>, Self: Sized,

Transforms a stream into a collection, returning a future representing the result of that computation. Read more
Source§

fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB> ⓘ
where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Stream<Item = (A, B)>,

Converts a stream of pairs into a future, which resolves to pair of containers. Read more
Source§

fn concat(self) -> Concat<Self> ⓘ
where Self: Sized, Self::Item: Extend<<Self::Item as IntoIterator>::Item> + IntoIterator + Default,

Concatenate all items of a stream into a single extendable destination, returning a future representing the end result. Read more
Source§

fn count(self) -> Count<Self> ⓘ
where Self: Sized,

Drives the stream to completion, counting the number of items. Read more
Source§

fn cycle(self) -> Cycle<Self>
where Self: Sized + Clone,

Repeats a stream endlessly. Read more
Source§

fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F> ⓘ
where F: FnMut(T, Self::Item) -> Fut, Fut: Future<Output = T>, Self: Sized,

Execute an accumulating asynchronous computation over a stream, collecting all the values into one final result. Read more
Source§

fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F> ⓘ
where F: FnMut(Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,

Execute predicate over asynchronous stream, and return true if any element in stream satisfied a predicate. Read more
Source§

fn all<Fut, F>(self, f: F) -> All<Self, Fut, F> ⓘ
where F: FnMut(Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,

Execute predicate over asynchronous stream, and return true if all element in stream satisfied a predicate. Read more
Source§

fn flatten(self) -> Flatten<Self>
where Self::Item: Stream, Self: Sized,

Flattens a stream of streams into just one continuous stream. Read more
Source§

fn flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> FlattenUnorderedWithFlowController<Self, ()>
where Self::Item: Stream + Unpin, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
Flattens a stream of streams into just one continuous stream. Polls inner streams produced by the base stream concurrently. Read more
Source§

fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
where F: FnMut(Self::Item) -> U, U: Stream, Self: Sized,

Maps a stream like StreamExt::map but flattens nested Streams. Read more
Source§

fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> FlatMapUnordered<Self, U, F>
where U: Stream + Unpin, F: FnMut(Self::Item) -> U, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
Maps a stream like StreamExt::map but flattens nested Streams and polls them concurrently, yielding items in any order, as they made available. Read more
Source§

fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
where F: FnMut(&mut S, Self::Item) -> Fut, Fut: Future<Output = Option<B>>, Self: Sized,

Combinator similar to StreamExt::fold that holds internal state and produces a new stream. Read more
Source§

fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
where F: FnMut(&Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,

Skip elements on this stream while the provided asynchronous predicate resolves to true. Read more
Source§

fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
where F: FnMut(&Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,

Take elements from this stream while the provided asynchronous predicate resolves to true. Read more
Source§

fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
where Fut: Future, Self: Sized,

Take elements from this stream until the provided future resolves. Read more
Source§

fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F> ⓘ
where F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()>, Self: Sized,

Runs this stream to completion, executing the provided asynchronous closure for each element on the stream. Read more
Source§

fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> ForEachConcurrent<Self, Fut, F> ⓘ
where F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()>, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
Runs this stream to completion, executing the provided asynchronous closure for each element on the stream concurrently as elements become available. Read more
Source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Creates a new stream of at most n items of the underlying stream. Read more
Source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Creates a new stream which skips n items of the underlying stream. Read more
Source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Fuse a stream such that poll_next will never again be called once it has finished. This method can be used to turn any Stream into a FusedStream. Read more
Source§

fn by_ref(&mut self) -> &mut Self

Borrows a stream, rather than consuming it. Read more
Source§

fn catch_unwind(self) -> CatchUnwind<Self>
where Self: Sized + UnwindSafe,

Available on crate feature std only.
Catches unwinding panics while polling the stream. Read more
Source§

fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
where Self: Sized + Send + 'a,

Available on crate feature alloc only.
Wrap the stream in a Box, pinning it. Read more
Source§

fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>
where Self: Sized + 'a,

Available on crate feature alloc only.
Wrap the stream in a Box, pinning it. Read more
Source§

fn buffered(self, n: usize) -> Buffered<Self>
where Self::Item: Future, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
An adaptor for creating a buffered list of pending futures. Read more
Source§

fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
where Self::Item: Future, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
An adaptor for creating a buffered list of pending futures (unordered). Read more
Source§

fn zip<St>(self, other: St) -> Zip<Self, St>
where St: Stream, Self: Sized,

An adapter for zipping two streams together. Read more
Source§

fn chain<St>(self, other: St) -> Chain<Self, St>
where St: Stream<Item = Self::Item>, Self: Sized,

Adapter for chaining two streams. Read more
Source§

fn peekable(self) -> Peekable<Self>
where Self: Sized,

Creates a new stream which exposes a peek method. Read more
Source§

fn chunks(self, capacity: usize) -> Chunks<Self>
where Self: Sized,

Available on crate feature alloc only.
An adaptor for chunking up items of the stream inside a vector. Read more
Source§

fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>
where Self: Sized,

Available on crate feature alloc only.
An adaptor for chunking up ready items of the stream inside a vector. Read more
Source§

fn forward<S>(self, sink: S) -> Forward<Self, S> ⓘ
where S: Sink<Self::Ok, Error = Self::Error>, Self: Sized + TryStream,

Available on crate feature sink only.
A future that completes after the given stream has been fully processed into the sink and the sink has been flushed and closed. Read more
Source§

fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
where Self: Sized + Sink<Item>,

Available on target_has_atomic=ptr and crate feature alloc and crate feature sink only.
Splits this Stream + Sink object into separate Sink and Stream objects. Read more
Source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where F: FnMut(&Self::Item), Self: Sized,

Do something with each item of this stream, afterwards passing it on. Read more
Source§

fn left_stream<B>(self) -> Either<Self, B> ⓘ
where B: Stream<Item = Self::Item>, Self: Sized,

Wrap this stream in an Either stream, making it the left-hand variant of that Either. Read more
Source§

fn right_stream<B>(self) -> Either<B, Self> ⓘ
where B: Stream<Item = Self::Item>, Self: Sized,

Wrap this stream in an Either stream, making it the right-hand variant of that Either. Read more
Source§

fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>
where Self: Unpin,

A convenience method for calling Stream::poll_next on Unpin stream types.
Source§

fn select_next_some(&mut self) -> SelectNextSome<'_, Self> ⓘ
where Self: Unpin + FusedStream,

Returns a Future that resolves when the next item in this stream is ready. Read more
Source§

impl<Args, S, E, C> TaskSink<Args, Durable> for S
where S: Sink<Task<<C as Codec<Args>>::Compact>, Error = E> + Unpin + Backend<Error = E> + WireFormatBackend<Codec = C> + BackendConfig<Args = Args, Kind = Durable> + Send, Args: Send, <C as Codec<Args>>::Compact: Send, C: Codec<Args> + Clone + Send + Sync, E: Send, <C as Codec<Args>>::Error: Error + Send + Sync + 'static,

Source§

fn start_send( self: Pin<&mut S>, item: Task<Args>, ) -> Result<(), TaskSinkError<<S as Backend>::Error>>

Begins sending a task to the sink. Read more
Source§

fn poll_ready( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Result<(), TaskSinkError<<S as Backend>::Error>>>

Polls the sink until it is ready to accept another task. Read more
Source§

fn poll_flush( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Result<(), TaskSinkError<<S as Backend>::Error>>>

Polls the sink until all previously submitted tasks have been flushed. Read more
Source§

fn poll_close( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Result<(), TaskSinkError<<S as Backend>::Error>>>

Polls the sink until it has been closed. Read more
Source§

async fn push( &mut self, task: Args, ) -> Result<(), TaskSinkError<<S as Backend>::Error>>

Pushes a single task into the backend. Read more
Source§

async fn push_bulk( &mut self, tasks: Vec<Args>, ) -> Result<(), TaskSinkError<<S as Backend>::Error>>

Pushes multiple tasks into the backend. Read more
Source§

async fn push_stream( &mut self, tasks: impl Stream<Item = Args> + Unpin + Send, ) -> Result<(), TaskSinkError<<S as Backend>::Error>>

Pushes tasks from a stream into the backend. Read more
Source§

async fn push_task( &mut self, task: Task<Args>, ) -> Result<(), TaskSinkError<<S as Backend>::Error>>

Pushes a fully constructed task into the backend. Read more
Source§

async fn push_all( &mut self, tasks: impl Stream<Item = Task<Args>> + Unpin + Send, ) -> Result<(), TaskSinkError<<S as Backend>::Error>>

Pushes fully constructed tasks from a stream into the backend. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T, E> TryStream for S
where S: Stream<Item = Result<T, E>> + ?Sized,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

type Error = E

The type of failures yielded by this future
Source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more
Source§

impl<S> TryStreamExt for S
where S: TryStream + ?Sized,

Source§

fn err_into<E>(self) -> ErrInto<Self, E>
where Self: Sized, Self::Error: Into<E>,

Wraps the current stream in a new stream which converts the error type into the one provided. Read more
Source§

fn map_ok<T, F>(self, f: F) -> MapOk<Self, F>
where Self: Sized, F: FnMut(Self::Ok) -> T,

Wraps the current stream in a new stream which maps the success value using the provided closure. Read more
Source§

fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
where Self: Sized, F: FnMut(Self::Error) -> E,

Wraps the current stream in a new stream which maps the error value using the provided closure. Read more
Source§

fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
where F: FnMut(Self::Ok) -> Fut, Fut: TryFuture<Error = Self::Error>, Self: Sized,

Chain on a computation for when a value is ready, passing the successful results to the provided closure f. Read more
Source§

fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F>
where F: FnMut(Self::Error) -> Fut, Fut: TryFuture<Ok = Self::Ok>, Self: Sized,

Chain on a computation for when an error happens, passing the erroneous result to the provided closure f. Read more
Source§

fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F>
where F: FnMut(&Self::Ok), Self: Sized,

Do something with the success value of this stream, afterwards passing it on. Read more
Source§

fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
where F: FnMut(&Self::Error), Self: Sized,

Do something with the error value of this stream, afterwards passing it on. Read more
Source§

fn into_stream(self) -> IntoStream<Self>
where Self: Sized,

Wraps a TryStream into a type that implements Stream Read more
Source§

fn try_next(&mut self) -> TryNext<'_, Self> ⓘ
where Self: Unpin,

Creates a future that attempts to resolve the next item in the stream. If an error is encountered before the next item, the error is returned instead. Read more
Source§

fn try_for_each<Fut, F>(self, f: F) -> TryForEach<Self, Fut, F> ⓘ
where F: FnMut(Self::Ok) -> Fut, Fut: TryFuture<Ok = (), Error = Self::Error>, Self: Sized,

Attempts to run this stream to completion, executing the provided asynchronous closure for each element on the stream. Read more
Source§

fn try_skip_while<Fut, F>(self, f: F) -> TrySkipWhile<Self, Fut, F>
where F: FnMut(&Self::Ok) -> Fut, Fut: TryFuture<Ok = bool, Error = Self::Error>, Self: Sized,

Skip elements on this stream while the provided asynchronous predicate resolves to true. Read more
Source§

fn try_take_while<Fut, F>(self, f: F) -> TryTakeWhile<Self, Fut, F>
where F: FnMut(&Self::Ok) -> Fut, Fut: TryFuture<Ok = bool, Error = Self::Error>, Self: Sized,

Take elements on this stream while the provided asynchronous predicate resolves to true. Read more
Source§

fn try_for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> TryForEachConcurrent<Self, Fut, F> ⓘ
where F: FnMut(Self::Ok) -> Fut, Fut: Future<Output = Result<(), Self::Error>>, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
Attempts to run this stream to completion, executing the provided asynchronous closure for each element on the stream concurrently as elements become available, exiting as soon as an error occurs. Read more
Source§

fn try_collect<C>(self) -> TryCollect<Self, C> ⓘ
where C: Default + Extend<Self::Ok>, Self: Sized,

Attempt to transform a stream into a collection, returning a future representing the result of that computation. Read more
Source§

fn try_chunks(self, capacity: usize) -> TryChunks<Self>
where Self: Sized,

Available on crate feature alloc only.
An adaptor for chunking up successful items of the stream inside a vector. Read more
Source§

fn try_ready_chunks(self, capacity: usize) -> TryReadyChunks<Self>
where Self: Sized,

Available on crate feature alloc only.
An adaptor for chunking up successful, ready items of the stream inside a vector. Read more
Source§

fn try_filter<Fut, F>(self, f: F) -> TryFilter<Self, Fut, F>
where Fut: Future<Output = bool>, F: FnMut(&Self::Ok) -> Fut, Self: Sized,

Attempt to filter the values produced by this stream according to the provided asynchronous closure. Read more
Source§

fn try_filter_map<Fut, F, T>(self, f: F) -> TryFilterMap<Self, Fut, F>
where Fut: TryFuture<Ok = Option<T>, Error = Self::Error>, F: FnMut(Self::Ok) -> Fut, Self: Sized,

Attempt to filter the values produced by this stream while simultaneously mapping them to a different type according to the provided asynchronous closure. Read more
Source§

fn try_flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> TryFlattenUnordered<Self>
where Self::Ok: TryStream + Unpin, <Self::Ok as TryStream>::Error: From<Self::Error>, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
Flattens a stream of streams into just one continuous stream. Produced streams will be polled concurrently and any errors will be passed through without looking at them. If the underlying base stream returns an error, it will be immediately propagated. Read more
Source§

fn try_flatten(self) -> TryFlatten<Self>
where Self::Ok: TryStream, <Self::Ok as TryStream>::Error: From<Self::Error>, Self: Sized,

Flattens a stream of streams into just one continuous stream. Read more
Source§

fn try_fold<T, Fut, F>(self, init: T, f: F) -> TryFold<Self, Fut, T, F> ⓘ
where F: FnMut(T, Self::Ok) -> Fut, Fut: TryFuture<Ok = T, Error = Self::Error>, Self: Sized,

Attempt to execute an accumulating asynchronous computation over a stream, collecting all the values into one final result. Read more
Source§

fn try_concat(self) -> TryConcat<Self> ⓘ
where Self: Sized, Self::Ok: Extend<<Self::Ok as IntoIterator>::Item> + IntoIterator + Default,

Attempt to concatenate all items of a stream into a single extendable destination, returning a future representing the end result. Read more
Source§

fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>
where Self::Ok: TryFuture<Error = Self::Error>, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
Attempt to execute several futures from a stream concurrently (unordered). Read more
Source§

fn try_buffered(self, n: usize) -> TryBuffered<Self>
where Self::Ok: TryFuture<Error = Self::Error>, Self: Sized,

Available on target_has_atomic=ptr and crate feature alloc only.
Attempt to execute several futures from a stream concurrently. Read more
Source§

fn try_poll_next_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll<Option<Result<Self::Ok, Self::Error>>>
where Self: Unpin,

A convenience method for calling TryStream::try_poll_next on Unpin stream types.
Source§

fn try_all<Fut, F>(self, f: F) -> TryAll<Self, Fut, F> ⓘ
where Self: Sized, F: FnMut(Self::Ok) -> Fut, Fut: Future<Output = bool>,

Attempt to execute a predicate over an asynchronous stream and evaluate if all items satisfy the predicate. Exits early if an Err is encountered or if an Ok item is found that does not satisfy the predicate. Read more
Source§

fn try_any<Fut, F>(self, f: F) -> TryAny<Self, Fut, F> ⓘ
where Self: Sized, F: FnMut(Self::Ok) -> Fut, Fut: Future<Output = bool>,

Attempt to execute a predicate over an asynchronous stream and evaluate if any items satisfy the predicate. Exits early if an Err is encountered or if an Ok item is found that satisfies the predicate. Read more