Skip to main content

Extensions

Struct Extensions 

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

The runner’s extensions, each under the namespace the host gave it. Origins are positions here: the host is OriginId::HOST and the extension at index i is OriginId(i + 1), which is what an event’s origin indexes back into.

Implementations§

Source§

impl Extensions

Source

pub fn new() -> Self

Source

pub fn push(&mut self, ext: Box<dyn Extension>) -> Result<(), String>

Adds ext under its own name as the namespace — import fs binds fs. push_as with an empty namespace, which means the same.

Source

pub fn push_as( &mut self, namespace: impl Into<String>, ext: Box<dyn Extension>, ) -> Result<(), String>

Adds ext under namespace — import fs as left. An empty namespace means the extension’s own name: the rule is here, once, so that a host taking the namespace from outside the program (a C argument, a Node option, a Lua call) passes it through rather than substituting name() first — three of them did, and a fourth did not. Fails when that name is empty too, when the namespace is already taken (two extensions cannot share one, since slot names would collide), or when a slot the extension lists contains the separator (a slot name is the extension’s own word; the host adds the namespace).

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn by_origin( &mut self, origin: OriginId, ) -> Option<&mut (dyn Extension + 'static)>

The extension an event’s origin names, if any. None while that extension is drawing — nothing routes events mid-frame — and for an origin no extension has.

Source

pub fn namespace_of(&self, origin: OriginId) -> Option<&str>

The namespace the host gave the extension at origin.

Source

pub fn asked_by(&self, origin: OriginId) -> OriginId

Who declared the slot the extension at origin last filled, and so where its replies go: OriginId::HOST unless another extension declared it.

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &dyn Extension)>

Every (namespace, extension), in origin order.

Source

pub fn route( &mut self, events: impl IntoIterator<Item = UiEvent>, to_host: impl FnMut(UiEvent), )

Delivers events to the extensions they came from and hands to_host everything addressed to the host: the host’s own events, and the replies of every extension whose slot the host declared.

A reply from an extension a guest placed goes to that guest instead, as one more event — its origin still the replier’s, so the receiver knows who spoke — and whatever the guest answers travels the same way, up to MAX_REPLY_HOPS levels. This is the loop all four hosts route with; one that grew its own would disagree with the others about who hears a nested plugin.

Trait Implementations§

Source§

impl Default for Extensions

Source§

fn default() -> Self

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

impl Fill for Extensions

The runner’s loop, as a Fill. A declared name is split at its last / into the namespace and the extension’s own slot name; the extension under that namespace fills it if it lists the name (or the name is "root" and it lists none). A view that errors leaves its message in the tree (red, where the fill would have been) and raises extension-view-error, once per extension and slot.

Source§

fn fill(&mut self, full_name: &str, key: Key, params: &Value, ui: &mut Ui<'_>)

Fill the slot declared as full_name now, at the cursor, with key its key: for the extension it names, ui.fill(origin, slot, |ui| ext.view(slot, ui)), which is where the namespace and the bound come from.
Source§

fn finish(&mut self, ui: &mut Ui<'_>)

After the host’s view: fill every ns/root the host did not declare, and warn about every slot an extension names that nothing declared this frame.
Source§

fn add( &mut self, namespace: &str, ext: Box<dyn Extension>, ) -> Result<OriginId, String>

Loads ext under namespace, mid-frame, and answers with the origin it got — what a guest that hosts guests of its own calls (env.add_extension in Lua). It joins the same list as everyone else, so namespace has to be free of the host’s names too. Read more
Source§

impl TryFrom<Vec<Box<dyn Extension>>> for Extensions

Source§

fn try_from(exts: Vec<Box<dyn Extension>>) -> Result<Self, String>

Each under its own name; fails as push does — two extensions of one name need push_as.

Source§

type Error = String

The type returned in the event of a conversion error.

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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