Skip to main content

ComponentCtx

Struct ComponentCtx 

Source
pub struct ComponentCtx<'ctx, 'local, 'env> { /* private fields */ }
Expand description

The scoped, opaque call context every NativeComponent method builds through — see the module doc’s decision 1.

Two things it is not: it is not the plugin’s own per-platform NativeCtx (which stays internal, so its helper surface can keep changing), and it is not a handle you may store — it borrows the live platform context of the one create/update/dispose call on the stack and cannot outlive it.

§The error latch

NativeComponent’s methods return no Result. Instead every fallible helper here latches its failure on the context and answers None, and report_error lets a component latch one of its own. The runtime reads the latch when the method returns: on create a latched error is fatal only if the component also answered None; on update it keeps the diff baseline unchanged and marks the slot for retry (the module doc’s A failed update is retried on the next rebuild); on dispose it is logged.

The first error wins, and every later one is logged rather than dropped. Reporting keeps the failure that started the cascade, not its last symptom — but a symptom is still evidence, so a latch that refuses a later error says so in the log (log::warn!), naming both. That holds across with_local_frame too, which is the one place a second context exists to lose an error in: the latch travels into the frame and back out, so failed() answers the same inside it as outside, on every platform arm.

§The slot it speaks for

A context also knows which slot the call is for — privately. That is what attach_listener binds the platform’s one listener to, and it is never handed to the component: a component can only ever route an event back to its own slot (the module doc’s Listener attachment).

Implementations§

Source§

impl ComponentCtx<'_, '_, '_>

Source

pub fn failed(&self) -> bool

Whether a platform call made through this context has already failed — the early-out a component checks before continuing to build against a handle that may not exist.

Source

pub fn report_error(&mut self, message: impl Into<String>)

Latch a failure of the component’s own (a platform call it made through the escape hatch, a precondition it found broken). Only the first latched error is kept.

Source§

impl ComponentCtx<'_, '_, '_>

Source

pub fn record(&mut self, call: impl Into<String>)

Record one would-be platform call — the host stand-in’s whole surface, so a component’s create/update/dispose can be asserted by an ordinary cargo test on a machine with no JNI and no Objective-C runtime at all. Compiled only on a host with no platform arm; there is no native view to build there.

Source

pub fn root(&mut self, identity: u64) -> Option<NativeRoot>

Take a stand-in root view with the given identity — the host mirror of the three platform arms’ root, where identity plays the role Env::is_same_object plays on Android (what a dispose resolves against).

Source

pub fn add_child(&mut self, parent: u64, child: u64) -> Option<()>

Record one would-be addView/addSubview — the host mirror of the three platform arms’ add_child, so a subtree’s plan is assertable (which child went under which parent, in what order) on a machine with no view hierarchy at all.

Source

pub fn retain_child(&mut self, identity: u64) -> Option<NativeChild>

Take a stand-in retained child handle — the host mirror of Android’s global reference and the Apple arms’ Retained.

Live handles are counted process-thread-wide (this module’s crate-private live_child_count), so a host test asserts the paired release the way ART’s global-ref count does on device (module doc’s Teardown) rather than merely asserting that nothing panicked.

Source

pub fn attach_listener( &mut self, view: u64, kinds: ListenerKinds, ) -> Option<ListenerHandle>

Record a would-be listener attach on the stand-in view view — the host mirror of the three platform arms’ attach_listener, so a component’s listener wiring is part of its assertable plan.

Like the real arms it binds the stand-in to this context’s own slot (logged, never recorded in the plan, never handed out), and it latches and answers None for an empty kinds. Live stand-in handles are counted (live_listener_count) the way Self::retain_child’s are.

Source

pub fn detach_listener(&mut self, handle: ListenerHandle) -> Option<()>

Record a would-be detach of what handle attached, then release it — the host mirror of the three platform arms’ detach_listener.

Source

pub fn with_local_frame<T>( &mut self, capacity: usize, f: impl FnOnce(&mut ComponentCtx<'_, '_, '_>) -> Option<T>, ) -> Option<T>

Record a would-be PushLocalFrame/PopLocalFrame pair around f — the host mirror of Android’s real local frame, so a test can assert a subtree build actually ran inside one.

Like the iOS arm, this hands the closure the caller’s own context, so the error latch is shared: failed() reads the same inside the frame as outside it, and a second error raised inside it is logged by the latch rather than dropped. Android reproduces both properties over a context it is forced to build fresh.

Auto Trait Implementations§

§

impl<'ctx, 'local, 'env> !UnwindSafe for ComponentCtx<'ctx, 'local, 'env>

§

impl<'ctx, 'local, 'env> Freeze for ComponentCtx<'ctx, 'local, 'env>

§

impl<'ctx, 'local, 'env> RefUnwindSafe for ComponentCtx<'ctx, 'local, 'env>

§

impl<'ctx, 'local, 'env> Send for ComponentCtx<'ctx, 'local, 'env>

§

impl<'ctx, 'local, 'env> Sync for ComponentCtx<'ctx, 'local, 'env>

§

impl<'ctx, 'local, 'env> Unpin for ComponentCtx<'ctx, 'local, 'env>

§

impl<'ctx, 'local, 'env> UnsafeUnpin for ComponentCtx<'ctx, 'local, 'env>

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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

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

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

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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

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