Skip to main content

Command

Struct Command 

Source
pub struct Command<Msg> { /* private fields */ }
Expand description

A batch of effects to run, possibly empty: background tasks, synchronous or asynchronous, and focus and scroll requests addressed by widget key.

Implementations§

Source§

impl<Msg: Send + 'static> Command<Msg>

Source

pub fn none() -> Self

No effect at all.

Source

pub fn batch(commands: impl IntoIterator<Item = Command<Msg>>) -> Self

Groups several commands into one.

Source

pub fn after(delay: Duration, message: Msg) -> Self

Delivers message once, after delay.

This waits without occupying anything: natively it is a task on the shell’s executor parked on the reactor’s timer wheel, and on the Web a setTimeout. A hundred pending timers are a hundred entries in a queue, not a hundred threads.

For a message that repeats, declare a Subscription::every instead — a subscription is a function of the state and stops when the state says so, where a chain of afters has to be stopped by hand.

Source

pub fn perform(task: impl FnOnce() -> Msg + Send + 'static) -> Self

Runs a synchronous task in the background; its result becomes a message.

Source

pub fn run(task: impl FnOnce() -> Option<Msg> + Send + 'static) -> Self

Runs a synchronous side effect; it may return a message (None for none).

Source

pub fn perform_async<F>(future: F) -> Self
where F: Future<Output = Msg> + Send + 'static,

Runs an asynchronous future; its value becomes a message.

On the Web, which is single-threaded, the browser drives the future (spawn_local), so a real fetch can await without blocking. Natively it runs on the shell’s executor (the runtime module), which has a reactor: a future may wait on a timer or on a socket and costs nothing while it does.

Do not put a blocking call in here — that is what Command::perform is for. The executor has four worker threads, and a blocking call holds one of them for its whole duration.

Source

pub fn run_async<F>(future: F) -> Self
where F: Future<Output = Option<Msg>> + Send + 'static,

Runs an asynchronous future for its side effect; it may return a message (None for none). The asynchronous counterpart of Command::run.

Source

pub fn focus(key: impl Hash) -> Self

Requests focus for the widget carrying key — the field wrapped in keyed(key, …). The shell resolves it after the view is next built; it is typically returned when a form submission fails, to jump to the first invalid field (Form::first_invalid).

Source

pub fn scroll(key: impl Hash, to: ScrollTo) -> Self

Moves a scroll region: the one named key goes where to says.

A scroll is not a function of the state — the same list, the same offset, and yet “go back to the top” happens once — so it is an effect and belongs here rather than on a widget. The offset it changes is state, and it stays where it was: in the runtime, beside every other offset, written by the frame this request is resolved into.

Named the way a focus request is named: the region is wrapped in keyed(k, …) and addressed by k. The framework’s own identities are hashes of a position in a tree, which an application cannot know and should not have to.

Resolved against the frame that follows, once and once only — the same rule as Command::focus. A request naming a region that frame has not got is dropped rather than kept waiting: an effect that outlived the state it was written for would arrive at a list that had since become somebody else’s.

Command::scroll("journal", ScrollTo::start())
Source

pub fn sheet(key: impl Hash, to: SheetTo) -> Self

Moves a sheet: the one named key goes where to says — the reference’s DraggableScrollableController, as an effect.

For the reason a scroll is one: “raise the sheet” happens once, and the height it leaves behind is state that stays where every other sheet height is, in the runtime. Named the same way — the sheet, or anything around it, wrapped in keyed(k, …) — and resolved on the same terms: against the frame that follows, a sheet that has only just appeared included, and dropped if that frame has not got it. A finger on the sheet refuses it.

Command::sheet("places", SheetTo::size(1.0).animate(0.3, Curve::ease()))
Source

pub fn is_empty(&self) -> bool

true when the command has no effect and no request of any kind.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Command<Msg>

§

impl<Msg> !Sync for Command<Msg>

§

impl<Msg> !UnwindSafe for Command<Msg>

§

impl<Msg> Freeze for Command<Msg>
where Vec<Box<dyn FnOnce() -> Option<Msg> + Send>>: Freeze, Vec<Pin<Box<dyn Future<Output = Option<Msg>> + Send>>>: Freeze, Vec<(Duration, Msg)>: Freeze,

§

impl<Msg> Send for Command<Msg>
where Vec<Box<dyn FnOnce() -> Option<Msg> + Send>>: Send, Vec<Pin<Box<dyn Future<Output = Option<Msg>> + Send>>>: Send, Vec<(Duration, Msg)>: Send,

§

impl<Msg> Unpin for Command<Msg>
where Vec<Box<dyn FnOnce() -> Option<Msg> + Send>>: Unpin, Vec<Pin<Box<dyn Future<Output = Option<Msg>> + Send>>>: Unpin, Vec<(Duration, Msg)>: Unpin,

§

impl<Msg> UnsafeUnpin for Command<Msg>
where Vec<Box<dyn FnOnce() -> Option<Msg> + Send>>: UnsafeUnpin, Vec<Pin<Box<dyn Future<Output = Option<Msg>> + Send>>>: UnsafeUnpin, Vec<(Duration, Msg)>: UnsafeUnpin,

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<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more