Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Vec reference or slice to function #893

Open
seanlinsley opened this issue Dec 1, 2024 · 1 comment
Open

Pass Vec reference or slice to function #893

seanlinsley opened this issue Dec 1, 2024 · 1 comment
Labels

Comments

@seanlinsley
Copy link

#288 (comment) 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.

@udoprog
Copy link
Collaborator

udoprog commented Dec 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants