pub struct ScriptHost { /* private fields */ }Expand description
Loaded native script factories. Instances created by this host keep the library loaded even if the host is dropped, so their callback vtables remain valid.
Implementations§
Source§impl ScriptHost
impl ScriptHost
Sourcepub fn from_defs(defs: Vec<ScriptDef>) -> Result<Self, String>
pub fn from_defs(defs: Vec<ScriptDef>) -> Result<Self, String>
Creates a host for permanently linked Rust scripts, useful for embedding and headless tests. Rejects empty or duplicate script names. Factories must belong to permanent host code, not an unloadable library.
use kvas_engine::script::{Script, ScriptDef, ScriptHost};
#[derive(Default)] struct Behaviour;
impl Script for Behaviour {}
let host = ScriptHost::from_defs(vec![ScriptDef::of::<Behaviour>("Behaviour")]).unwrap();
assert!(host.create("Behaviour").is_some());Sourcepub fn load(path: &Path) -> Result<ScriptHost, String>
pub fn load(path: &Path) -> Result<ScriptHost, String>
Loads a library. It is copied first so the original stays writable for the next build.
Sourcepub fn names(&self) -> Vec<&str>
pub fn names(&self) -> Vec<&str>
Exported type names borrowed for the host lifetime (not falsely 'static).
Use Self::names_owned to retain names across hot reload or host drop.
Sourcepub fn names_owned(&self) -> Vec<String>
pub fn names_owned(&self) -> Vec<String>
Copies exported names so they can be retained after the library is unloaded.
Auto Trait Implementations§
impl Freeze for ScriptHost
impl RefUnwindSafe for ScriptHost
impl Send for ScriptHost
impl Sync for ScriptHost
impl Unpin for ScriptHost
impl UnsafeUnpin for ScriptHost
impl UnwindSafe for ScriptHost
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
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> MaybeSync for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.