pub trait Function {
type Datum<'c>;
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;
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
fn chunk_name(&self) -> Option<&str>
fn chunk_name(&self) -> Option<&str>
Chunk name which was used to create function (if known)
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,
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
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_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
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_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
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_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
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_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
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,
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