tildeio / helix

Native Ruby extensions without fear

Home Page:https://usehelix.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation example doesn't compile (in several different ways)

alyssais opened this issue · comments

I'm trying to compile this example from the documentation:

#[use_macros]
extern crate helix;

ruby! {
    class Line {
        struct {
            p1: Point,
            p2: Point
        }

        def initialize(helix, p1: Point, p2: Point) {
            Line { helix, p1, p2 }
        }

        def distance(&self) {
            let (dx, dy) = (self.p1.x - self.p2.x, self.p1.y - self.p2.y);
            dx.hypot(dy)
        }
    }

    class Point {
        struct {
            x: f64,
            y: f64
        }

        def initialize(helix, x: f64, y: f64) {
            Point { helix, x, y }
        }

        join(&self, second: &Point) -> Line {
            
            Line {
                p1: Point { x: self.x, y: self.y },
                p2: Point { x: second.x, y: second.y }
            }
        }
    }
}

I get this error:

error: cannot find macro `ruby!` in this scope
 --> src/lib.rs:4:1
  |
4 | ruby! {
  | ^^^^

error: aborting due to previous error

I'm new to Rust, so working out exactly what's going on here is difficult for me, but I worked out that I should probably replace #[use_macros] with #[macro_use] since that's what the Rails generator does. Making that change, I instead get this error:

error: no rules expected the token `parse_methods`
  --> src/lib.rs:4:1
   |
4  | / ruby! {
5  | |     class Line {
6  | |         struct {
7  | |             p1: Point,
...  |
38 | |     }
39 | | }
   | |_^
   |
   = note: this error originates in a macro outside of the current crate

Now, if I comment out all the method definitions apart from Point#initialize, and the Line struct, it compiles, but when I try to add any other methods — those that use other Helix classes, I get an error like this:

error[E0277]: the trait bound `helix::<unnamed>::VALUE: helix::UncheckedValue<Point>` is not satisfied
  --> src/lib.rs:5:1
   |
5  | / ruby! {
6  | |
7  | |     class Line {
8  | |         struct {
...  |
41 | |
42 | | }
   | |_^ the trait `helix::UncheckedValue<Point>` is not implemented for `helix::<unnamed>::VALUE`
   |
   = help: the following implementations were found:
             <helix::<unnamed>::VALUE as helix::UncheckedValue<&'a [usize]>>
             <helix::<unnamed>::VALUE as helix::UncheckedValue<std::string::String>>
             <helix::<unnamed>::VALUE as helix::UncheckedValue<bool>>
             <helix::<unnamed>::VALUE as helix::UncheckedValue<u64>>
           and 9 others
   = note: required by `helix::UncheckedValue::to_checked`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `helix::CheckedValue<Point>: helix::ToRust<_>` is not satisfied
  --> src/lib.rs:5:1
   |
5  | / ruby! {
6  | |
7  | |     class Line {
8  | |         struct {
...  |
41 | |
42 | | }
   | |_^ the trait `helix::ToRust<_>` is not implemented for `helix::CheckedValue<Point>`
   |
   = help: the following implementations were found:
             <helix::CheckedValue<&'a [usize]> as helix::ToRust<&'a [usize]>>
             <helix::CheckedValue<std::string::String> as helix::ToRust<std::string::String>>
             <helix::CheckedValue<bool> as helix::ToRust<bool>>
             <helix::CheckedValue<u64> as helix::ToRust<u64>>
           and 9 others
   = note: required by `helix::ToRust::to_rust`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `helix::CheckedValue<Point>: helix::ToRust<_>` is not satisfied
  --> src/lib.rs:5:1
   |
5  | / ruby! {
6  | |
7  | |     class Line {
8  | |         struct {
...  |
41 | |
42 | | }
   | |_^ the trait `helix::ToRust<_>` is not implemented for `helix::CheckedValue<Point>`
   |
   = help: the following implementations were found:
             <helix::CheckedValue<&'a [usize]> as helix::ToRust<&'a [usize]>>
             <helix::CheckedValue<std::string::String> as helix::ToRust<std::string::String>>
             <helix::CheckedValue<bool> as helix::ToRust<bool>>
             <helix::CheckedValue<u64> as helix::ToRust<u64>>
           and 9 others
   = note: required by `helix::ToRust::to_rust`
   = note: this error originates in a macro outside of the current crate

error: aborting due to 3 previous errors

My guess is this is (partially?) just out-of-date documentation. I'm really excited about this project, and am looking forward to seeing how it develops. :)

There are definitely some issues in the docs here. Sorry about that! I'm investigating.