rune
rune copied to clipboard
Pass Vec reference or slice to function
https://github.com/rune-rs/rune/issues/288#issuecomment-960639458 suggests that Vm::call should accept references, but when modifying the vector.rs example I can't get either &Vec or &[] to work:
error[E0277]: the trait bound `&std::vec::Vec<{integer}>: AnyMarker` is not satisfied
--> examples/examples/vector.rs:40:37
|
40 | let output = vm.call(["calc"], (&input,))?;
| ---- ^^^^^^ the trait `AnyMarker` is not implemented for `&std::vec::Vec<{integer}>`
| |
| required by a bound introduced by this call
error[E0277]: the trait bound `&[{integer}]: AnyMarker` is not satisfied
--> examples/examples/vector.rs:40:37
|
40 | let output = vm.call(["calc"], (input.as_slice(),))?;
| ---- ^^^^^^^^^^^^^^^^ the trait `AnyMarker` is not implemented for `&[{integer}]`
| |
| required by a bound introduced by this call
Also to confirm, if it did compile, will the input still be used by the function as a reference or is it internally cloned/serialized? It's important not to clone it to avoid performance bottlenecks.
It cannot accept slices directly, since we wouldn't know what yo do with them. You'd have to wrap the type passed in into something deriving Any. Like a newtype. That gives it a type hash anf a name which is needed for Rune to deal with it directly.