Trait jlrs::call::ProvideKeywords
source · [−]pub trait ProvideKeywords<'value, 'data>: Call<'data> {
fn provide_keywords(
self,
keywords: Value<'value, 'data>
) -> JlrsResult<WithKeywords<'value, 'data>>;
}
Expand description
Provide keyword arguments to a Julia function.
Required Methods
fn provide_keywords(
self,
keywords: Value<'value, 'data>
) -> JlrsResult<WithKeywords<'value, 'data>>
fn provide_keywords(
self,
keywords: Value<'value, 'data>
) -> JlrsResult<WithKeywords<'value, 'data>>
Provide keyword arguments to the function. The keyword arguments must be a NamedTuple
.
Example:
julia.scope(|global, mut frame| unsafe {
// The code we evaluate is a simple function definition, which is safe.
let func = unsafe {
Value::eval_string(&mut frame, "func(; a=3, b=4, c=5) = a + b + c")?
.into_jlrs_result()?
};
let a = Value::new(&mut frame, 1isize)?;
let b = Value::new(&mut frame, 2isize)?;
let nt = named_tuple!(&mut frame, "a" => a, "b" => b)?;
// Call the previously defined function. This function simply sums its three
// keyword arguments and has no side effects, so it's safe to call.
let res = unsafe {
func.provide_keywords(nt)?
.call0(&mut frame)?
.into_jlrs_result()?
.unbox::<isize>()?
};
assert_eq!(res, 8);
Ok(())
})