pub trait Pluggable: PluggableFields + PluggableMethods {
// Required method
fn name(&self) -> &'static str;
// Provided methods
fn fields(&self) -> Vec<Field> { ... }
fn methods(&self) -> Vec<Method> { ... }
fn class(&self) -> Class { ... }
}Expand description
An object that can be plugged into a scripting language.
Can be automatically derived by placing #[pluggable] on a struct.
When implementing Pluggable, it is necessary to have both a struct and an
impl, with both having the #[pluggable] attribute.
This has been split up into two other traits
PluggableFields- `PluggableMethods
This is because the syntax extender can not see all of the code -
it can only see the thing it’s operating on. This is why we need
an attribute on the struct and the impl. We can’t implement
a trait twice, each time overriding a specific method.
Because of this, it is necessary to mark both the struct and the impl
with the pluggable attribute. It’s not the prettiest, but it does work.
Required Methods§
Provided Methods§
fn fields(&self) -> Vec<Field>
fn methods(&self) -> Vec<Method>
fn class(&self) -> Class
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".