diff options
| author | Teddy Wing | 2018-08-16 13:23:40 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-08-16 13:23:40 +0200 | 
| commit | ae48205ed1549678835574f962c7d2c62704d147 (patch) | |
| tree | 0c5d2d076c8c56d9f58ce52bebd402c048d61cab | |
| parent | 33f8d8cea1eb67fe9f73aad34891b85ccf37e4cc (diff) | |
| download | dome-key-map-ae48205ed1549678835574f962c7d2c62704d147.tar.bz2 | |
Parse single map definitions
Parse a map definition line into a `Map`.
Got so stuck on this error:
    error[E0277]: the trait bound `(): combine::Parser` is not satisfied
       --> src/lib.rs:107:16
        |
    107 | fn map<I>() -> impl Parser<Input = I, Output = Map>
        |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `combine::Parser` is not implemented for `()`
        |
        = note: the return type of a function must have a statically known size
    error: aborting due to previous error
    For more information about this error, try `rustc --explain E0277`.
Turns out the problem was that I had put a semicolon at the end of the
expression in `map()`. Geez. Took hours to finally see that.
| -rw-r--r-- | src/lib.rs | 35 | 
1 files changed, 35 insertions, 0 deletions
| @@ -35,6 +35,7 @@ pub struct MapAction {      pub kind: MapKind,  } +#[derive(Debug, PartialEq)]  struct Map {      trigger: Trigger,      action: Action, @@ -103,6 +104,26 @@ where      skip_many1(space().or(tab()))  } +fn map<I>() -> impl Parser<Input = I, Output = Map> +where +    I: Stream<Item = char>, +    I::Error: ParseError<I::Item, I::Range, I::Position>, +{ +    ( +        map_kind(), +        whitespace_separator(), +        trigger(), +        whitespace_separator(), +        action() +    ).map(|(kind, _, trigger, _, action)| +        Map { +            trigger: trigger, +            action: action, +            kind: kind, +        } +    ) +} +  fn map_collection<I>() -> impl Parser<Input = I, Output = MapCollection>  where      I: Stream<Item = char>, @@ -196,6 +217,20 @@ mod tests {      }      #[test] +    fn map_parses_map_line() { +        let text = "map <play><down> test +"; +        let expected = Map { +            trigger: vec![HeadphoneButton::Play, HeadphoneButton::Down], +            action: "test".to_owned(), +            kind: MapKind::Map, +        }; +        let result = map().parse(text).map(|t| t.0); + +        assert_eq!(result, Ok(expected)); +    } + +    #[test]      fn map_collection_parses_maps() {          let text = "  map <up><down> test | 
