Trait sandkiste::Function

source ·
pub trait Function {
    type Datum<'c>;

    // Required methods
    fn chunk_name(&self) -> Option<&str>;
    fn call<'c, A>(
        &self,
        args: A
    ) -> Result<Vec<Self::Datum<'static>>, MachineError>
       where A: IntoIterator<Item = Self::Datum<'c>>,
             <A as IntoIterator>::IntoIter: ExactSizeIterator;

    // Provided methods
    fn call_expect_retvals<'c, A>(
        &self,
        count: usize,
        args: A
    ) -> Result<Vec<Self::Datum<'static>>, MachineError>
       where A: IntoIterator<Item = Self::Datum<'c>>,
             <A as IntoIterator>::IntoIter: ExactSizeIterator { ... }
    fn call_expect_min_retvals<'c, A>(
        &self,
        count: usize,
        args: A
    ) -> Result<Vec<Self::Datum<'static>>, MachineError>
       where A: IntoIterator<Item = Self::Datum<'c>>,
             <A as IntoIterator>::IntoIter: ExactSizeIterator { ... }
    fn call_1ret<'c, A>(
        &self,
        args: A
    ) -> Result<Self::Datum<'static>, MachineError>
       where A: IntoIterator<Item = Self::Datum<'c>>,
             <A as IntoIterator>::IntoIter: ExactSizeIterator { ... }
    fn call_2ret<'c, A>(
        &self,
        args: A
    ) -> Result<(Self::Datum<'static>, Self::Datum<'static>), MachineError>
       where A: IntoIterator<Item = Self::Datum<'c>>,
             <A as IntoIterator>::IntoIter: ExactSizeIterator { ... }
    fn call_3ret<'c, A>(
        &self,
        args: A
    ) -> Result<(Self::Datum<'static>, Self::Datum<'static>, Self::Datum<'static>), MachineError>
       where A: IntoIterator<Item = Self::Datum<'c>>,
             <A as IntoIterator>::IntoIter: ExactSizeIterator { ... }
}
Expand description

Basic interface of function that runs in a Machine

Example

use sandkiste::prelude::*;

fn perform_numeric_operation<F>(func: F, a: i32, b: i32) -> i32
where
    F: Function,
    for<'c> <F as Function>::Datum<'c>: MaybeInteger,
{
    func
        .call_1ret([a.into(), b.into()])
        .expect("runtime error")
        .try_as_i32().expect("type error")
}

Required Associated Types§

source

type Datum<'c>

Type used for arguments and return values

Required Methods§

source

fn chunk_name(&self) -> Option<&str>

Chunk name which was used to create function (if known)

source

fn call<'c, A>( &self, args: A ) -> Result<Vec<Self::Datum<'static>>, MachineError>where A: IntoIterator<Item = Self::Datum<'c>>, <A as IntoIterator>::IntoIter: ExactSizeIterator,

Call the function

Provided Methods§

source

fn call_expect_retvals<'c, A>( &self, count: usize, args: A ) -> Result<Vec<Self::Datum<'static>>, MachineError>where A: IntoIterator<Item = Self::Datum<'c>>, <A as IntoIterator>::IntoIter: ExactSizeIterator,

Same as Function::call but expects a fixed number of return values

source

fn call_expect_min_retvals<'c, A>( &self, count: usize, args: A ) -> Result<Vec<Self::Datum<'static>>, MachineError>where A: IntoIterator<Item = Self::Datum<'c>>, <A as IntoIterator>::IntoIter: ExactSizeIterator,

Same as Function::call but expects a minimum number of return values

source

fn call_1ret<'c, A>( &self, args: A ) -> Result<Self::Datum<'static>, MachineError>where A: IntoIterator<Item = Self::Datum<'c>>, <A as IntoIterator>::IntoIter: ExactSizeIterator,

Same as Function::call but expects exactly one return value

source

fn call_2ret<'c, A>( &self, args: A ) -> Result<(Self::Datum<'static>, Self::Datum<'static>), MachineError>where A: IntoIterator<Item = Self::Datum<'c>>, <A as IntoIterator>::IntoIter: ExactSizeIterator,

Same as Function::call but expects exactly two return values

source

fn call_3ret<'c, A>( &self, args: A ) -> Result<(Self::Datum<'static>, Self::Datum<'static>, Self::Datum<'static>), MachineError>where A: IntoIterator<Item = Self::Datum<'c>>, <A as IntoIterator>::IntoIter: ExactSizeIterator,

Same as Function::call but expects exactly three return values

Implementors§