d-unsed / ruru

Native Ruby extensions written in Rust
MIT License
832 stars 40 forks source link

Methods calling methods within methods! macro fail because parameter requirements #74

Open danielpclark opened 7 years ago

danielpclark commented 7 years ago

Now that I know this I can implement my code so it will work around this issue, but it's not convenient and I don't see any info on this. Consider this more of a documentation request.

Here's the scenario:

methods!(
  FasterPathname,
  _itself,

  fn r_dirname() -> RString { pub_dirname(r_to_path()) }
  fn pub_dirname(pth: RString) -> RString {
    Boolean::new(
      Path::new(
        pth.ok().unwrap_or(RString::new("")).to_str()
      ).is_dir()
    )
  }
);

And the method r_to_path simple gets the instance variable @path. When I try to run the above code I get errors that both the pub_dirname method call and r_to_path method call need three parameters. When I throw in some random values it tells me that the signature for those parameters need to be:

i32, *-ptr, FasterPathname

Even with methods that take extra parameters it still says three and asks for this same signature. So I'm assuming the methods! macro isn't allowing methods to be calling each other from within the methods! macro. I'll be moving all of my code out of it externally to implement both of my public/private alternative implementations that respectively work with or without the instance variable @path.