Macro aanyx::import_plugin

source ·
macro_rules! import_plugin {
    ( dyn $plugin_type:ident ) => { ... };
    ( $plugin_type:ident ) => { ... };
}
Expand description

This is a macro that generates the name of the plugin declaration in a module. Using this makes easier to check type compatibility between plugins and host systems, because if the plugin doesn’t support the requested plugin type then no declaration will be found.

use aanyx::import_plugin;
assert_eq!( import_plugin!( MyPlugin ), b"plugin_declaration_MyPlugin");
assert_eq!( import_plugin!( dyn MyPluginTrait ), b"plugin_declaration_dyn_MyPluginTrait");

Limitations

Because of Rust macros limitations a type cannot contains ::. This means that this is invalid:

use aanyx::import_plugin;
import_plugin!( myplugin::MyPlugin )

A workaround is the following:

use myplugin::MyPlugin as MyPlugin;
use aanyx::import_plugin;
 
import_plugin!( MyPlugin );

Also using a type alias makes a result not compatible between host and plugin.

use aanyx::import_plugin;
use myplugin::MyPlugin as MyPlugin;
type MyAlias = MyPlugin;
 
assert_ne!( import_plugin!( MyAlias ), import_plugin!( MyPlugin ) );