std::plugin
API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。
load a plugin into this program and call its functions.
A plugin is a package built with lib: { kind: "plugin" }. It shares
this program's runtime: what it returns are ordinary values here
(str, List, closures, any, sums), and a type of a package both
use is the same type on both sides.
let p = try plugin::load(plugin::beside("enemies"));
let spawn = try p.get::<fn(i32) -> List<str>>("enemies::spawn");
println(spawn(3).len());
Structs
PluginSource
pub struct PluginA loaded plugin. Copies name the same plugin.
Its package name.
Its package version.
The file it was loaded from.
Sourcepub fn get<F>(§self, path: str) throws (PluginError) -> F The function
path("enemies::spawn"), of typeF: apub fnof the plugin's package declared with exactly that type.
Sourcepub fn get_static<T>(§self, path: str) throws (PluginError) -> T The value of static
path("enemies::LEVEL") of typeT.The types it describes: those its code asks
core::reflectabout and the types they are made of. Do not use one after the plugin is unloaded.Stop finding it, and unload it once nothing of it is alive: no value of its types, no function of it held or running, no plugin using it.
Enums
UnloadSource
pub enum UnloadWhat Plugin::unload did.
Unloaded: nothing of it was alive.
No longer found by
get; it goes once nothing of it is alive. The text says what still holds it.Stays loaded: the text says why.
PluginErrorSource
pub enum PluginErrorWhy a plugin did not load, or an item was not found. Each message says what to do.
No file at
path.The file is not a Nabi plugin (a C library, a program).
Built by another toolchain than this program.
Built for another target than this program.
Packages the plugin takes from the program, which has none of them.
Items the plugin takes from the program, which has none of them.
A type the program and the plugin both have is laid out differently (built with other features).
The plugin has no
pub fn(or static) atpath.pathhas another type than the one asked for:have(empty when unknown).The plugin was unloaded.
The system loader failed.
What went wrong and what to do, for display.
Trait implementations 1
impl Display for PluginError
Functions
fileSource
pub fn file(name: str) -> str The file name a plugin package name builds to on this target:
libname.dylib, libname.so or name.dll.
besideSource
pub fn beside(name: str) -> str The path of plugin name's file beside this program's executable:
where nabi build puts a plugin: true dependency.
loadSource
pub fn load(path: str) throws (PluginError) -> Plugin Load the plugin at path (a bare file name is in the current
directory). Loading one that is loaded gives the same plugin.
loadedSource
pub fn loaded() -> List<Plugin> The plugins loaded and not unloaded, in load order.
wait_unloadedSource
pub fn wait_unloaded(p: Plugin, ms: u64) -> bool Wait until p is unloaded for good (Unload::Pending), at most
ms milliseconds, collecting garbage meanwhile; whether it is.