pub struct Command<Effect, Event> { /* private fields */ }
Implementations§
Source§impl<Effect, Event> Command<Effect, Event>
impl<Effect, Event> Command<Effect, Event>
Sourcepub fn new<F, Fut>(create_task: F) -> Self
pub fn new<F, Fut>(create_task: F) -> Self
Create a new command orchestrating effects with async Rust. This is the lowest level
API to create a Command if you need full control over its execution. In most cases you will
more likely want to create Commands with capabilities, and using the combinator APIs
([then
], [and
] and [all
]) to orchestrate them.
The create_task
closure receives a [CommandContext
] that it can use to send shell requests,
events back to the app, and to spawn additional tasks. The closure is expected to return a future
which becomes the command’s main asynchronous task.
Sourcepub fn done() -> Self
pub fn done() -> Self
Create an empty, completed Command. This is useful as a return value from update
if
there are no side-effects to perform.
Sourcepub fn event(event: Event) -> Self
pub fn event(event: Event) -> Self
Create a Command which dispatches an event and terminates. This is an alternative
to calling update
recursively. The only difference is that the two update
calls
will be visible to Crux and can show up in logs or any tooling. The trade-off is that
the event is not guaranteed to dispatch instantly - another update
call which is
already scheduled may happen first.
Sourcepub fn notify_shell<Op>(operation: Op) -> Command<Effect, Event>
pub fn notify_shell<Op>(operation: Op) -> Command<Effect, Event>
Create a Command which sends a notification to the shell with a provided operation
.
This ia synchronous equivalent of [CommandContext::notify_shell
].
Sourcepub fn request_from_shell<Op>(
operation: Op,
) -> RequestBuilder<Effect, Event, impl Future<Output = Op::Output>>
pub fn request_from_shell<Op>( operation: Op, ) -> RequestBuilder<Effect, Event, impl Future<Output = Op::Output>>
Start a creation of a Command which sends a one-time request to the shell with a provided operation.
Returns a RequestBuilder
, which can be converted into a Command directly, or chained
with another command builder using .then
.
In an async context, RequestBuilder
can be turned into a future that resolves to the
operation output type.
Sourcepub fn stream_from_shell<Op>(
operation: Op,
) -> StreamBuilder<Effect, Event, impl Stream<Item = Op::Output>>
pub fn stream_from_shell<Op>( operation: Op, ) -> StreamBuilder<Effect, Event, impl Stream<Item = Op::Output>>
Start a creation of a Command which sends a stream request to the shell with a provided operation.
Returns a StreamBuilder
, which can be converted into a Command directly, or chained
with a RequestBuilder
builder using .then
.
In an async context, StreamBuilder
can be turned into a stream that with the
operation output type as item.
Sourcepub fn is_done(&mut self) -> bool
pub fn is_done(&mut self) -> bool
Run the effect state machine until it settles, then return true if there is any more work to do - tasks to run or events or effects to receive
Sourcepub fn effects(&mut self) -> impl Iterator<Item = Effect> + '_
pub fn effects(&mut self) -> impl Iterator<Item = Effect> + '_
Run the effect state machine until it settles and collect all effects generated
Sourcepub fn events(&mut self) -> impl Iterator<Item = Event> + '_
pub fn events(&mut self) -> impl Iterator<Item = Event> + '_
Run the effect state machine until it settles and collect all events generated
Sourcepub fn then(self, other: Self) -> Self
pub fn then(self, other: Self) -> Self
Create a command running self and the other command in sequence
Sourcepub fn and(self, other: Self) -> Self
pub fn and(self, other: Self) -> Self
Convenience for Command::all
which runs another command concurrently with this one
Sourcepub fn map_effect<F, NewEffect>(self, map: F) -> Command<NewEffect, Event>
pub fn map_effect<F, NewEffect>(self, map: F) -> Command<NewEffect, Event>
Map effects requested as part of this command to a different effect type.
This is useful when composing apps to convert a command from a child app to a command of the parent app.
Sourcepub fn map_event<F, NewEvent>(self, map: F) -> Command<Effect, NewEvent>
pub fn map_event<F, NewEvent>(self, map: F) -> Command<Effect, NewEvent>
Map events sent as part of this command to a different effect type
This is useful when composing apps to convert a command from a child app to a command of the parent app.
Sourcepub fn abort_handle(&self) -> AbortHandle
pub fn abort_handle(&self) -> AbortHandle
Returns an abort handle which can be used to remotely terminate a running Command and all its subtask.
This is specifically useful for cancelling subscriptions and long running effects which may get superseded, like timers
Trait Implementations§
Source§impl<Effect, Event> Stream for Command<Effect, Event>
impl<Effect, Event> Stream for Command<Effect, Event>
Auto Trait Implementations§
impl<Effect, Event> Freeze for Command<Effect, Event>
impl<Effect, Event> !RefUnwindSafe for Command<Effect, Event>
impl<Effect, Event> Send for Command<Effect, Event>
impl<Effect, Event> !Sync for Command<Effect, Event>
impl<Effect, Event> Unpin for Command<Effect, Event>
impl<Effect, Event> !UnwindSafe for Command<Effect, Event>
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
§impl<T> StreamExt for Twhere
T: Stream + ?Sized,
impl<T> StreamExt for Twhere
T: Stream + ?Sized,
§fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
§fn into_future(self) -> StreamFuture<Self>
fn into_future(self) -> StreamFuture<Self>
§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
§fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
§fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
§fn collect<C>(self) -> Collect<Self, C>
fn collect<C>(self) -> Collect<Self, C>
§fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
§fn concat(self) -> Concat<Self>
fn concat(self) -> Concat<Self>
§fn count(self) -> Count<Self>where
Self: Sized,
fn count(self) -> Count<Self>where
Self: Sized,
§fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
§fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
true
if any element in stream satisfied a predicate. Read more§fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
true
if all element in stream satisfied a predicate. Read more§fn flatten(self) -> Flatten<Self>where
Self::Item: Stream,
Self: Sized,
fn flatten(self) -> Flatten<Self>where
Self::Item: Stream,
Self: Sized,
§fn flatten_unordered(
self,
limit: impl Into<Option<usize>>,
) -> FlattenUnorderedWithFlowController<Self, ()>
fn flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> FlattenUnorderedWithFlowController<Self, ()>
§fn flat_map_unordered<U, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> FlatMapUnordered<Self, U, F>
fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> FlatMapUnordered<Self, U, F>
StreamExt::map
] but flattens nested Stream
s
and polls them concurrently, yielding items in any order, as they made
available. Read more§fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
StreamExt::fold
] that holds internal state
and produces a new stream. Read more§fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
true
. Read more§fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
true
. Read more§fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
§fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
§fn for_each_concurrent<Fut, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> ForEachConcurrent<Self, Fut, F>
fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> ForEachConcurrent<Self, Fut, F>
§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n
items of the underlying stream. Read more§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n
items of the underlying stream. Read more§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
§fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
§fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
§fn buffered(self, n: usize) -> Buffered<Self>
fn buffered(self, n: usize) -> Buffered<Self>
§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
§fn zip<St>(self, other: St) -> Zip<Self, St>where
St: Stream,
Self: Sized,
fn zip<St>(self, other: St) -> Zip<Self, St>where
St: Stream,
Self: Sized,
§fn chain<St>(self, other: St) -> Chain<Self, St>where
St: Stream<Item = Self::Item>,
Self: Sized,
fn chain<St>(self, other: St) -> Chain<Self, St>where
St: Stream<Item = Self::Item>,
Self: Sized,
§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where
Self: Sized,
peek
method. Read more§fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
§fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
§fn forward<S>(self, sink: S) -> Forward<Self, S>where
S: Sink<Self::Ok, Error = Self::Error>,
Self: Sized + TryStream,
fn forward<S>(self, sink: S) -> Forward<Self, S>where
S: Sink<Self::Ok, Error = Self::Error>,
Self: Sized + TryStream,
§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
§fn left_stream<B>(self) -> Either<Self, B>where
B: Stream<Item = Self::Item>,
Self: Sized,
fn left_stream<B>(self) -> Either<Self, B>where
B: Stream<Item = Self::Item>,
Self: Sized,
§fn right_stream<B>(self) -> Either<B, Self>where
B: Stream<Item = Self::Item>,
Self: Sized,
fn right_stream<B>(self) -> Either<B, Self>where
B: Stream<Item = Self::Item>,
Self: Sized,
§fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
Stream::poll_next
] on Unpin
stream types.