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
impl CExtension
Sourcepub unsafe fn open(path: impl AsRef<Path>) -> Result<Self, String>
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
impl Drop for CExtension
Source§impl Extension for CExtension
impl Extension for CExtension
fn name(&self) -> &str
Source§fn slots(&self) -> &[String]
fn slots(&self) -> &[String]
"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.fn view(&mut self, slot: &Slot<'_>, ui: &mut Ui<'_>) -> Result<(), String>
Auto Trait Implementations§
impl !Send for CExtension
impl !Sync for CExtension
impl Freeze for CExtension
impl RefUnwindSafe for CExtension
impl Unpin for CExtension
impl UnsafeUnpin for CExtension
impl UnwindSafe for CExtension
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.