rune icon indicating copy to clipboard operation
rune copied to clipboard

Should `#[rune::function]` be associated if function returns `Self`

Open ModProg opened this issue 2 years ago • 1 comments

There is only detection in place for functions that take self, but not for e.g. constructors that return Self:

impl Struct {
    #[rune::function]
    fn new(it: usize) -> Self {
        Self(it)
    }
}

Fails with:

error[E0425]: cannot find value `__rune_fn__new` in this scope
  --> crates/rune/src/tests/rune_derive.rs:12:8
   |
12 |     fn new(it: usize) -> Self {
   |        ^^^ not found in this scope
   |
help: consider using the associated function
   |
12 |     fn Self::new(it: usize) -> Self {
   |        ++++++
help: consider importing this function
   |
1  + use crate::modules::bytes::__rune_fn__new;
   |

ModProg avatar Aug 07 '23 08:08 ModProg

Hm, yeah maybe. Interesting suggestion!

udoprog avatar Aug 07 '23 10:08 udoprog