Trait dusk_api::Freight[][src]

pub trait Freight {
    fn get_function_list(&mut self) -> Vec<Function>;
fn call_function(
        &mut self,
        function_number: u64,
        args: Vec<&mut Box<dyn Any>>
    ) -> Result<Box<dyn Any>, RuntimeError>; fn init(
        &mut self,
        _limitations: &Option<Vec<Limitation>>
    ) -> Vec<InterplugRequest> { ... }
fn update_limitations(&mut self, _limitations: &Vec<Limitation>) { ... }
fn interplug_provide(
        &mut self,
        _request: InterplugRequest,
        _freight_proxy: Rc<FreightProxy>
    ) { ... }
fn interplug_deny(&mut self, _request: InterplugRequest) { ... }
fn get_type_list(&mut self) -> Vec<Type> { ... }
fn get_operator_list(&mut self) -> Vec<Function> { ... } }

Trait, that defines the plugin behavior

This trait must be implemented in plugins to allow the program, that uses them to call any internal function of choice. For that the trait has a method Freight::get_function_list, that provides argument types and return types, actually being used under Any trait as well as the function name to refer to it and its identification number, which is needed to call this function

The Freight::call_function method actually calls the function, which matches the provided id.

Example

pub struct Test;

impl Freight for Test {
    fn call_function (
        self: &mut Self,
        function_number: u64,
        mut args: Vec<&mut Box<dyn Any>>
        ) -> Result<Box<dyn Any>, RuntimeError> {

        match function_number {
            0 => return Ok(Box::new(
                    args[0].downcast_mut::<String>()
                        .unwrap()
                        .clone())
                ),
            _ => return Err(RuntimeError::Message{
                    msg: "bad fn number"
                }),
        }
    }

    fn get_function_list (self: &mut Self) -> Vec<Function> {
        let mut result: Vec<Function> = Vec::new();
        result.push(Function{
            name: "copy",
            number: 0,
            arg_types: vec![TypeId::of::<String>()],
            return_type: TypeId::of::<String>(),
        });
        return result;
    }

    fn get_type_list (self: &mut Self) -> Vec<Type> {
        return Vec::new();
    }
}

Required methods

fn get_function_list(&mut self) -> Vec<Function>[src]

Function that is used to provide information about internal functions of a plugin to the program using it, so it can choose the function it needs either by its name, argument types, return type or all of the above

fn call_function(
    &mut self,
    function_number: u64,
    args: Vec<&mut Box<dyn Any>>
) -> Result<Box<dyn Any>, RuntimeError>
[src]

Function that is used to call proxy the calls from the outside of a plugin to the internal functions and must implement function calling, by its number arguments, contained inside of Vec<Box<dyn Any>> and must return either a Box<dyn Any> representing the returned value or a RuntimeError

Loading content...

Provided methods

fn init(
    &mut self,
    _limitations: &Option<Vec<Limitation>>
) -> Vec<InterplugRequest>
[src]

Function that is ran when importing the plugin, which may be reimplememented in a plugin if it needs to set up some things before doing any other actions

If some system limitations should be applied, they must be included as an argument. If the plugin needs to use other plugins, it should request them as a Vector of InterplugRequest

fn update_limitations(&mut self, _limitations: &Vec<Limitation>)[src]

Function that updates system limitations

fn interplug_provide(
    &mut self,
    _request: InterplugRequest,
    _freight_proxy: Rc<FreightProxy>
)
[src]

Function that replies to the interplugin request by providing the requested plugin

fn interplug_deny(&mut self, _request: InterplugRequest)[src]

Function that replies to the interplugin request by by informing it that the request was denied

fn get_type_list(&mut self) -> Vec<Type>[src]

Function that is used to provide information about non standard types, a function from this plugin might take as an argument or return, so that the program using the plugin can take such non-standard objects from one function implemented in this plugin and pass it on into another function in this plugin

To use it, just reimplement it to return a vector of such Type structure descriptions

fn get_operator_list(&mut self) -> Vec<Function>[src]

Function that is used to provide information about internal functions of a plugin that are named after binary operators and should be treated as such. These functions have to always get exactly two arguments and they are called by the same function that calls any function Freight::call_function

Loading content...

Implementors

impl Freight for EmptyFreight[src]

impl Freight for FreightProxy[src]

Loading content...