pub struct EffectCx<R: Resource, H = ()> { /* private fields */ }Expand description
What an effect handler, a job’s completion and a projection drain receive: the resource, its dispatcher, and the means to start a job.
H is what a completion gets mutable access to: the surface that
handles the effect (&mut self), or () for a handler a view registered.
Implementations§
Source§impl<R: Resource, H: 'static> EffectCx<R, H>
impl<R: Resource, H: 'static> EffectCx<R, H>
Sourcepub fn place(&self) -> Option<&Place>
pub fn place(&self) -> Option<&Place>
Where the invoker asked this effect to act (its #[param(place)]
argument): act there instead of at their caret. Once it succeeds
for a participant, they land there (Live::place_of).
Sourcepub fn document(&self) -> Option<Ref<'_, Doc>>
pub fn document(&self) -> Option<Ref<'_, Doc>>
The resource’s document as it is now, to read what a view answers with: the state at its heads, a selection’s measurements, a picture of it. Only a surface’s handler answering an invocation has it; a job’s completion, which runs later, reads the live state instead. Changes go through the dispatcher, never here.
Sourcepub fn heads(&self) -> Vec<ChangeHash>
pub fn heads(&self) -> Vec<ChangeHash>
The heads of the document as it is now; empty without one.
Sourcepub fn version(&self, version: &str) -> Result<DocumentVersion, String>
pub fn version(&self, version: &str) -> Result<DocumentVersion, String>
The resource at version, as a caller names one: a change id from
its history (or enough of one) or a checkpoint’s name.
§Errors
Returns why version names no version of this document, or that
the handler has no document to read.
Sourcepub fn dispatcher(&self) -> Dispatcher<R>
pub fn dispatcher(&self) -> Dispatcher<R>
Where the effect’s document changes go: ordinary actions, checked, applied, undone and replicated like any other.
Sourcepub fn apply(&self, action: &R::Action)
pub fn apply(&self, action: &R::Action)
Submit one typed action, as Dispatcher::apply.
Sourcepub fn submit(&self, submit: impl Submit<R>)
pub fn submit(&self, submit: impl Submit<R>)
Submit a field edit or a verb, as Dispatcher::submit.
Sourcepub fn invocation(&self) -> Option<InvocationId>
pub fn invocation(&self) -> Option<InvocationId>
The actual source invocation this work continues. Ordinary background projection drains have none; causal drains retain the current Document caller. Its source identity may differ from the local reply operation.
Sourcepub fn approved_check(
&self,
check_id: &str,
) -> Result<ApprovedCheckFuture, String>
pub fn approved_check( &self, check_id: &str, ) -> Result<ApprovedCheckFuture, String>
Run an approved project check through this effect’s admitted host channel.
Commands, source paths and resource bounds are chosen by the project host.
Pass the returned future to the existing effect job with Self::spawn.
§Errors
Refuses projection drains, absent original custody or unavailable transport.
Sourcepub fn approved_check_reported(
&self,
check_id: &str,
) -> Result<impl FnOnce(Progress) -> ApprovedCheckFuture + Send + 'static + use<R, H>, String>
pub fn approved_check_reported( &self, check_id: &str, ) -> Result<impl FnOnce(Progress) -> ApprovedCheckFuture + Send + 'static + use<R, H>, String>
Attach approved-check reports to this action’s existing job progress. The app remains the sole publisher of invocation-update sequences.
§Errors
Refuses absent dispatch custody or unavailable approved transport.
Sourcepub fn waker(&self) -> WakeHandle
pub fn waker(&self) -> WakeHandle
Wakes the app from another thread, to draw what a worker changed.
Sourcepub fn spawn<T, F>(
&mut self,
work: impl FnOnce(Progress) -> F,
then: impl FnOnce(&mut H, T, &mut Self) -> EffectAnswer + 'static,
) -> Effected
pub fn spawn<T, F>( &mut self, work: impl FnOnce(Progress) -> F, then: impl FnOnce(&mut H, T, &mut Self) -> EffectAnswer + 'static, ) -> Effected
Run work’s future on the app runtime, then then with its output on
the UI thread. The future reports through the Progress it is
built with; cancelling the effect aborts it.
Sourcepub fn thread<T>(
&mut self,
work: impl FnOnce(Progress) -> T + Send + 'static,
then: impl FnOnce(&mut H, T, &mut Self) -> EffectAnswer + 'static,
) -> Effectedwhere
T: Send + 'static,
pub fn thread<T>(
&mut self,
work: impl FnOnce(Progress) -> T + Send + 'static,
then: impl FnOnce(&mut H, T, &mut Self) -> EffectAnswer + 'static,
) -> Effectedwhere
T: Send + 'static,
Run blocking work off the UI thread, then then with its result on
the UI thread. work reports through its Progress and checks it
for cancellation.
Sourcepub fn reply(&mut self) -> EffectReply
pub fn reply(&mut self) -> EffectReply
Answer later, from wherever the work settles. Return
Effected::Pending and keep the reply until then.
Sourcepub fn reply_then(
&mut self,
then: impl FnOnce(&mut H, ActionOutput, &mut Self) -> EffectAnswer + 'static,
) -> EffectReply
pub fn reply_then( &mut self, then: impl FnOnce(&mut H, ActionOutput, &mut Self) -> EffectAnswer + 'static, ) -> EffectReply
Answer later, then settle the successful receipt on the UI thread
under this effect’s retained invocation. Refusal skips the completion
and preserves its structured failure. Cancellation and current custody
are checked by the same job path as Self::spawn.
Sourcepub fn when_landed(
&mut self,
then: impl FnOnce(&mut H, Landed, &mut Self) -> EffectAnswer + 'static,
) -> EffectAnswer
pub fn when_landed( &mut self, then: impl FnOnce(&mut H, Landed, &mut Self) -> EffectAnswer + 'static, ) -> EffectAnswer
Answer once what this effect submitted through its
dispatcher landed: each submission goes through
the door like any other, checked again for the effect’s invoker, and
then runs with the last one’s [Landed] — what the door answered
(what an edit changed, as the resource’s surface reports it) and the
items it created — to reply to the effect’s caller. A refused
submission fails the effect with why. The effect must be declared
job, since it answers after the edits apply.
cx.dispatcher().submit(Doc::BODY.edit(op));
cx.when_landed(|_, landed, _| Ok(Effected::value(landed.answer)))§Errors
When the effect was not invoked (a view’s own job) or submitted nothing to wait for.
Sourcepub fn choose_file(
&mut self,
request: PickRequest,
then: impl FnOnce(&mut H, Option<ChosenFile>, &mut Self) -> EffectAnswer + 'static,
) -> Effected
pub fn choose_file( &mut self, request: PickRequest, then: impl FnOnce(&mut H, Option<ChosenFile>, &mut Self) -> EffectAnswer + 'static, ) -> Effected
Ask the person to choose a file with the host’s chooser (request
is an Open request), then run then on the UI thread with its name
and contents, or None when they cancelled. Works where files have
no paths, such as a browser page. Bound reads with
PickRequest::max_contents_bytes; an oversized selection fails the
job before calling then. The effect must be declared job.
Sourcepub fn choose_files(
&mut self,
request: PickRequest,
then: impl FnOnce(&mut H, Vec<ChosenFile>, &mut Self) -> EffectAnswer + 'static,
) -> Effected
pub fn choose_files( &mut self, request: PickRequest, then: impl FnOnce(&mut H, Vec<ChosenFile>, &mut Self) -> EffectAnswer + 'static, ) -> Effected
Self::choose_file for a request that lets the person choose
several files (PickRequest::open_multiple): then receives every
chosen file, none when they cancelled. A request contents limit applies
to the total bytes across the entire selection.
Sourcepub fn choose_path(
&mut self,
request: PickRequest,
then: impl FnOnce(&mut H, Option<PathBuf>, &mut Self) -> EffectAnswer + 'static,
) -> Effected
pub fn choose_path( &mut self, request: PickRequest, then: impl FnOnce(&mut H, Option<PathBuf>, &mut Self) -> EffectAnswer + 'static, ) -> Effected
Ask the person to choose a file with the host’s chooser and run
then on the UI thread with its path on this device, or None when
they cancelled: for a file the app reads in place rather than into
memory (a disk image, a video). Only a host whose files have paths
answers; elsewhere use Self::choose_file. The effect must be
declared job.
Sourcepub fn save_file(
&mut self,
request: PickRequest,
bytes: Vec<u8>,
then: impl FnOnce(&mut H, bool, &mut Self) -> EffectAnswer + 'static,
) -> Effected
pub fn save_file( &mut self, request: PickRequest, bytes: Vec<u8>, then: impl FnOnce(&mut H, bool, &mut Self) -> EffectAnswer + 'static, ) -> Effected
Ask the person where to save bytes with the host’s chooser
(request is a Save request suggesting a file name; a browser page
downloads them under it), then run then on the UI thread with
whether they were saved: false when the person cancelled. The
effect must be declared job.
Sourcepub fn open_here(
&mut self,
opener: &OpenHere,
arguments: &[String],
then: impl FnOnce(&mut H, Result<(), String>, &mut Self) -> EffectAnswer + 'static,
) -> Effected
pub fn open_here( &mut self, opener: &OpenHere, arguments: &[String], then: impl FnOnce(&mut H, Result<(), String>, &mut Self) -> EffectAnswer + 'static, ) -> Effected
Ask the host to show what a launch naming arguments opens in this
window, in place of the record it shows ([OpenHere::open]), then
run then on the UI thread with its answer: shown, or why not. The
answer arrives even when the window shows the new record before this
surface draws another frame. Cancelling the effect withdraws a
request the host has not taken up yet. The effect must be declared
job.
Auto Trait Implementations§
impl<R, H> Freeze for EffectCx<R, H>
impl<R, H = ()> !RefUnwindSafe for EffectCx<R, H>
impl<R, H = ()> !Send for EffectCx<R, H>
impl<R, H = ()> !Sync for EffectCx<R, H>
impl<R, H> Unpin for EffectCx<R, H>
impl<R, H> UnsafeUnpin for EffectCx<R, H>
impl<R, H = ()> !UnwindSafe for EffectCx<R, H>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more