Trait memflow::plugins::Loadable

source ·
pub trait Loadable: Sized {
    type Instance: StableAbi;
    type InputArg;
    type CInputArg: StableAbi;
    type ArgsType;

    // Required methods
    fn ident(&self) -> &str;
    fn plugin_type() -> &'static str;
    fn export_prefix() -> &'static str;
    fn new(descriptor: PluginDescriptor<Self>) -> Self;
    fn help(&self) -> Result<String>;
    fn target_list(&self) -> Result<Vec<TargetInfo>>;
    fn instantiate(
        &self,
        library: CArc<LibContext>,
        input: Self::InputArg,
        args: Option<&Self::ArgsType>
    ) -> Result<Self::Instance>;

    // Provided methods
    fn exists(&self, instances: &[LibInstance<Self>]) -> bool { ... }
    fn load(
        path: impl AsRef<Path>,
        library: &CArc<LibContext>,
        export: &str
    ) -> Result<LibInstance<Self>> { ... }
    fn load_all(path: impl AsRef<Path>) -> Result<Vec<LibInstance<Self>>> { ... }
    fn load_append(
        path: impl AsRef<Path>,
        out: &mut Vec<LibInstance<Self>>
    ) -> Result<()> { ... }
}
Expand description

Defines a common interface for loadable plugins

Required Associated Types§

Required Methods§

source

fn ident(&self) -> &str

Identifier string of the plugin

source

fn plugin_type() -> &'static str

source

fn export_prefix() -> &'static str

Constant prefix for the plugin type

source

fn new(descriptor: PluginDescriptor<Self>) -> Self

source

fn help(&self) -> Result<String>

Retrieves the help text for this plugin

source

fn target_list(&self) -> Result<Vec<TargetInfo>>

Retrieves the list of available targets for this plugin

source

fn instantiate( &self, library: CArc<LibContext>, input: Self::InputArg, args: Option<&Self::ArgsType> ) -> Result<Self::Instance>

Creates an Instance of the library

This function assumes that load performed necessary safety checks for validity of the library.

Provided Methods§

source

fn exists(&self, instances: &[LibInstance<Self>]) -> bool

Checks if plugin with the same ident already exists in input list

source

fn load( path: impl AsRef<Path>, library: &CArc<LibContext>, export: &str ) -> Result<LibInstance<Self>>

source

fn load_all(path: impl AsRef<Path>) -> Result<Vec<LibInstance<Self>>>

Try to load a plugin library

This function will access library and try to find corresponding entry for the plugin. If a valid plugins are found, Ok(LibInstance<Self>) is returned. Otherwise, Err(Error) is returned, with appropriate error.

Safety

Loading third party libraries is inherently unsafe and the compiler cannot guarantee that the implementation of the library matches the one specified here. This is especially true if the loaded library implements the necessary interface manually.

It is adviced to use a provided proc macro to define a valid library.

source

fn load_append( path: impl AsRef<Path>, out: &mut Vec<LibInstance<Self>> ) -> Result<()>

Helper function to load a plugin into a list of library instances

This function will try finding appropriate plugin entry, and add it into the list if there isn’t a duplicate entry.

Safety

Loading third party libraries is inherently unsafe and the compiler cannot guarantee that the implementation of the library matches the one specified here.

Object Safety§

This trait is not object safe.

Implementors§