Function

Trait Function 

Source
pub trait Function: Send + Sync {
    type Input<'a>: Deserialize<'a> + Send;
    type Output<'a>: Serialize + Send;

    // Required methods
    fn schema(&self, diags: &mut Diagnostics) -> Option<FunctionSchema>;
    fn call<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        params: Self::Input<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<Self::Output<'a>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for implementing a function with automatic serialization/deserialization

See also: DynamicFunction

Required Associated Types§

Source

type Input<'a>: Deserialize<'a> + Send

Function Input

The input will be automatically serialized/deserialized at the border of the request.

Source

type Output<'a>: Serialize + Send

Function Output

The output will be automatically serialized/deserialized at the border of the request.

Required Methods§

Source

fn schema(&self, diags: &mut Diagnostics) -> Option<FunctionSchema>

Get the schema of the function

§Arguments
  • diags - Diagnostics to record warnings and errors that occured when getting back the schema
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Source

fn call<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, params: Self::Input<'a>, ) -> Pin<Box<dyn Future<Output = Option<Self::Output<'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Call Function

§Arguments
  • diags - Diagnostics to record warnings and errors that occured when calling the function
  • params - Function parameters packed into the input type
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§