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<'_, '_, '_>
impl ComponentCtx<'_, '_, '_>
Sourcepub fn failed(&self) -> bool
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.
Sourcepub fn report_error(&mut self, message: impl Into<String>)
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<'_, '_, '_>
impl ComponentCtx<'_, '_, '_>
Sourcepub fn record(&mut self, call: impl Into<String>)
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.
Sourcepub fn root(&mut self, identity: u64) -> Option<NativeRoot>
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).
Sourcepub fn add_child(&mut self, parent: u64, child: u64) -> Option<()>
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.
Sourcepub fn retain_child(&mut self, identity: u64) -> Option<NativeChild>
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.
Sourcepub fn attach_listener(
&mut self,
view: u64,
kinds: ListenerKinds,
) -> Option<ListenerHandle>
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.
Sourcepub fn detach_listener(&mut self, handle: ListenerHandle) -> Option<()>
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.
Sourcepub fn with_local_frame<T>(
&mut self,
capacity: usize,
f: impl FnOnce(&mut ComponentCtx<'_, '_, '_>) -> Option<T>,
) -> Option<T>
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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.