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§
Required Methods§
sourcefn chunk_name(&self) -> Option<&str>
fn chunk_name(&self) -> Option<&str>
Chunk name which was used to create function (if known)
sourcefn call<'c, A>(
&self,
args: A
) -> Result<Vec<Self::Datum<'static>>, MachineError>where
A: IntoIterator<Item = Self::Datum<'c>>,
<A as IntoIterator>::IntoIter: ExactSizeIterator,
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§
sourcefn 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_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
sourcefn 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_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
sourcefn 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_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
sourcefn 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_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
sourcefn 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,
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