rune icon indicating copy to clipboard operation
rune copied to clipboard

`VecDeque` can't be sent through Rune

Open HoloTheDrunk opened this issue 1 year ago • 3 comments

Attempt

#[derive(Any)]
struct MyStruct {
    #[rune(get)]
    dvec: VecDeque<i64>,
}

Expected behaviour The code compiles without issue.

Actual behaviour The compiler throws this error:

error[E0277]: the trait bound `{closure@src/main.rs:8:10: 8:13}: InstanceFunction<_, Plain>` is not satisfied
    --> src/main.rs:8:10
     |
8    |   #[derive(Any)]
     |            ^^^ the trait `InstanceFunction<_, Plain>` is not implemented for closure `{closure@src/main.rs:8:10: 8:13}`
9    |   struct MyStruct {
10   | /     #[rune(get)]
11   | |     dvec: VecDeque<i64>,
     | |_______________________- required by a bound introduced by this call
     |
note: required by a bound in `rune::Module::field_function`
    --> /home/RDuhen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rune-0.13.2/src/module/module.rs:1603:12
     |
1595 |     pub fn field_function<N, F, A>(
     |            -------------- required by a bound in this associated function
...
1603 |         F: InstanceFunction<A, Plain>,
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Module::field_function`

Note Another error message I have not been able to reproduce said something along the lines of "VecDeque is missing a Rune clone implementation", which could be what's preventing passing VecDeques to a Rune VM.

HoloTheDrunk avatar Apr 23 '24 14:04 HoloTheDrunk

I think it's just lacking FromValue and ToValue implementations.

You'd also be encouraged to use rune::alloc::vec_deque, and the mapping would go to the VecDeque in the collections module.

udoprog avatar Apr 23 '24 15:04 udoprog

Ah, using rune::alloc::VecDeque leads to the Clone error I couldn't get again.

error[E0277]: the trait bound `rune::alloc::VecDeque<i64>: Clone` is not satisfied
 --> src/main.rs:8:10
  |
8 | #[derive(Any)]
  |          ^^^ the trait `Clone` is not implemented for `rune::alloc::VecDeque<i64>`
  |
  = note: this error originates in the derive macro `Any` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `{closure@src/main.rs:8:10: 8:13}: InstanceFunction<_, Plain>` is not satisfied
    --> src/main.rs:8:10
     |
8    |   #[derive(Any)]
     |            ^^^ the trait `InstanceFunction<_, Plain>` is not implemented for closure `{closure@src/main.rs:8:10: 8:13}`
9    |   struct MyStruct {
10   | /     #[rune(get)]
11   | |     dvec: rune::alloc::VecDeque<i64>,
     | |____________________________________- required by a bound introduced by this call
     |
note: required by a bound in `rune::Module::field_function`
    --> /home/RDuhen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rune-0.13.2/src/module/module.rs:1603:12
     |
1595 |     pub fn field_function<N, F, A>(
     |            -------------- required by a bound in this associated function
...
1603 |         F: InstanceFunction<A, Plain>,
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Module::field_function`

HoloTheDrunk avatar Apr 24 '24 09:04 HoloTheDrunk

Hmm. We should really be using TryClone and not Clone in the macro that builds the getter.

udoprog avatar Apr 25 '24 07:04 udoprog