Skip to main content

ExtensionDispatcher

Struct ExtensionDispatcher 

Source
pub struct ExtensionDispatcher { /* private fields */ }
Expand description

Owns registered extensions and routes messages to them.

Maintains a type-name index for O(1) dispatch, a node-to-extension map for event/command routing, and per-extension poison state for panic isolation. Created via ToddyAppBuilder::build_dispatcher.

Implementations§

Source§

impl ExtensionDispatcher

Source

pub fn new(extensions: Vec<Box<dyn WidgetExtension>>) -> Self

Source

pub fn clone_for_session(&self) -> Self

Create a new dispatcher for a multiplexed session.

Calls WidgetExtension::new_instance() on each registered extension to produce independent instances with isolated mutable state. The type-name index is rebuilt from the new instances.

Panics if any extension has not implemented new_instance().

Source

pub fn handles_type(&self, type_name: &str) -> bool

Check if a node type is handled by an extension.

Source

pub fn prepare_all( &mut self, root: &TreeNode, caches: &mut ExtensionCaches, theme: &Theme, )

Called after Core::apply() on tree changes.

Source

pub fn handle_event( &mut self, id: &str, family: &str, data: &Value, caches: &mut ExtensionCaches, ) -> EventResult

Handle a Message::Event.

Source

pub fn handle_command( &mut self, node_id: &str, op: &str, payload: &Value, caches: &mut ExtensionCaches, ) -> Vec<OutgoingEvent>

Handle an ExtensionCommand.

Source

pub fn init_all(&mut self, config: &Value)

Route configuration to extensions. config is the value of the extension_config key from Settings – a JSON object keyed by each extension’s config_key().

Source

pub fn render<'a>( &'a self, node: &'a TreeNode, env: &WidgetEnv<'a>, ) -> Option<Element<'a, Message>>

Render an extension node. Returns None if no extension handles this type.

The caller must construct the WidgetEnv and pass it in. This avoids a borrow-checker issue where a locally-constructed env would be dropped before the returned Element (which borrows from the env).

Note: catch_unwind happens in the caller (widgets::render) because the returned Element borrows from env and can’t be wrapped in a closure. When a render panic is caught, the caller should call record_render_panic to track consecutive failures.

Source

pub fn record_render_panic(&self, type_name: &str) -> bool

Record a render panic for the extension that handles type_name. Called by the catch_unwind wrapper in widgets::render (which has only &self). Uses AtomicU32 so no &mut self is required. Returns true if the extension has reached the poison threshold.

Source

pub fn clear_poisoned(&mut self)

Reset all poisoned flags and render panic counters. Called on Snapshot.

Source

pub fn cleanup_all(&mut self, caches: &mut ExtensionCaches)

Call cleanup() for every node currently tracked by the dispatcher.

Used before a full state reset (e.g. Reset message) so extensions get a chance to release per-node resources before their cache entries are wiped.

Source

pub fn reset(&mut self, caches: &mut ExtensionCaches)

Full reset: call cleanup for all tracked nodes, clear the node map, clear extension caches, and reset poisoned state.

Extensions themselves (the registered trait objects) are preserved – only per-node runtime state is wiped.

Source

pub fn is_empty(&self) -> bool

Check if any extensions are registered.

Source

pub fn len(&self) -> usize

Number of registered extensions.

Trait Implementations§

Source§

impl Default for ExtensionDispatcher

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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

Source§

fn downcast(&self) -> &T

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 + Send + Sync>

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> 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<State, Message> IntoBoot<State, Message> for State

Source§

fn into_boot(self) -> (State, Task<Message>)

Turns some type into the initial state of some Application.
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
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

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

Source§

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

Source§

fn vzip(self) -> V

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

impl<T> MaybeClone for T

Source§

impl<T> MaybeDebug for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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