Skip to main content

CExtension

Struct CExtension 

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

A C shared library loaded as a guest extension of a Rust host.

The plugin exports kui_ext_abi and kui_ext_view (and optionally kui_ext_name, kui_ext_init, kui_ext_slots, kui_ext_on_event and kui_ext_free; include/kui.h has the prototypes). Each frame the host’s Ui reaches a slot the plugin fills, kui_ext_view is called with a context borrowing that frame and builds into it with the ordinary kui_open / kui_text / kui_close calls; events from the nodes it built go to kui_ext_on_event, never to the host, and what it answers with kui_reply reaches the host with the plugin’s origin.

It implements Extension, so it plugs into kui_native::app(..) .extension_as(namespace, ext) or a kui_core::Extensions list like any other extension. On ELF and Mach-O the plugin links against nothing and resolves kui_* from the host executable at load, which needs the host linked with --export-dynamic (this crate’s build.rs does it for the examples); on Windows the plugin links against the host’s import library or against kui_ffi.dll.

use kui_ffi::CExtension;

// SAFETY: the plugin's code runs in this process; loading it is
// trusting it as much as linking it would be.
let ext = unsafe { CExtension::open("target/debug/panel.so") }?;
let launcher = kui_native::app("host").extension_as("todos", ext);

Implementations§

Source§

impl CExtension

Source

pub unsafe fn open(path: impl AsRef<Path>) -> Result<Self, String>

Loads the shared library at path and runs its kui_ext_init.

Fails, with the reason as the error, if the library will not load, if it declares no kui_ext_abi or one other than this build’s KUI_ABI_VERSION, or if it has no kui_ext_view. The plugin’s kui_ext_free runs and the library is unloaded when the CExtension is dropped.

§Safety

The library’s entry points are called on the host’s frame and its code runs in the host’s process: loading one is trusting it exactly as much as linking it would be.

Trait Implementations§

Source§

impl Drop for CExtension

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Extension for CExtension

Source§

fn name(&self) -> &str

Source§

fn slots(&self) -> &[String]

The slot names this extension fills; empty means "root". The one entry crate::slot::ANY_SLOT ("*") means every name declared under its namespace, for an extension whose slots are not known when it loads — a Lua host whose init.lua registers views at runtime, one slot per view — and it then gets no unknown-slot warning, since there is no list to check against.
Source§

fn view(&mut self, slot: &Slot<'_>, ui: &mut Ui<'_>) -> Result<(), String>

Source§

fn on_event(&mut self, ev: &UiEvent) -> Vec<Value>

One of this extension’s events; the values returned are replies to the host, delivered in order.

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

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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

Source§

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

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