Skip to content

Instantly share code, notes, and snippets.

@estsauver
Created February 8, 2015 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estsauver/004037a71f93bf0ec5f5 to your computer and use it in GitHub Desktop.
Save estsauver/004037a71f93bf0ec5f5 to your computer and use it in GitHub Desktop.
Function Implementation

I'm writing a parser combinator library. I thought maybe I could also make the parser structs functions that operate on input, but I can't get the types right. The offending code.

Earls-MacBook-Pro:farce earljstsauver$ head 10 src/parser.rs 
head: 10: No such file or directory
==> src/parser.rs <==
pub trait Parser<'b>: Fn(&str, Option<&str>) {
}


impl <'a> Fn(&str, Option<&str>) for LiteralParser<'a> {
  fn call(&self, args: &str) -> Option<&str> {
    None
  }
}

The error when I try and build it

Earls-MacBook-Pro:farce earljstsauver$ cargo build 
   Compiling farce v0.0.1 (file:///Users/earljstsauver/dev/rust/farce)
src/parser.rs:5:13: 5:33 error: associated type bindings are not allowed here [E0229]
src/parser.rs:5 impl <'a> Fn(&str, Option<&str>) for LiteralParser<'a> {
                            ^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `farce`.

To learn more, run the command again with --verbose.

How do I declare that I implement a function in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment