Skip to main content

EffectCx

Struct EffectCx 

Source
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>

Source

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).

Source

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.

Source

pub fn heads(&self) -> Vec<ChangeHash>

The heads of the document as it is now; empty without one.

Source

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.

Source

pub fn dispatcher(&self) -> Dispatcher<R>

Where the effect’s document changes go: ordinary actions, checked, applied, undone and replicated like any other.

Source

pub fn apply(&self, action: &R::Action)

Submit one typed action, as Dispatcher::apply.

Source

pub fn submit(&self, submit: impl Submit<R>)

Submit a field edit or a verb, as Dispatcher::submit.

Source

pub fn live(&self) -> &Live<R>

The resource’s live state.

Source

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.

Source

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.

Source

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.

Source

pub fn waker(&self) -> WakeHandle

Wakes the app from another thread, to draw what a worker changed.

Source

pub fn spawn<T, F>( &mut self, work: impl FnOnce(Progress) -> F, then: impl FnOnce(&mut H, T, &mut Self) -> EffectAnswer + 'static, ) -> Effected
where T: Send + 'static, F: Future<Output = T> + Send + 'static,

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.

Source

pub fn thread<T>( &mut self, work: impl FnOnce(Progress) -> T + Send + 'static, then: impl FnOnce(&mut H, T, &mut Self) -> EffectAnswer + 'static, ) -> Effected
where 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.

Source

pub fn reply(&mut self) -> EffectReply

Answer later, from wherever the work settles. Return Effected::Pending and keep the reply until then.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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> 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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

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

§

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.
§

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.
§

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.
§

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> Upcast<T> for T

§

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

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,