Created
December 2, 2021 18:06
-
-
Save petejohanson/df409904c1d2147205f4d509d7d0b0e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| warning: `part1` (bin "part1") generated 1 warning | |
| error: could not compile `part1` due to previous error; 1 warning emitted | |
| d474c7e06993:/workspace/day2/part1$ cargo run | |
| Compiling part1 v0.1.0 (/workspace/day2/part1) | |
| error[E0283]: type annotations needed | |
| --> src/main.rs:26:26 | |
| | | |
| 26 | let mut dir_parser = alt(( | |
| | -------------- ^^^ cannot infer type for type parameter `E` declared on the function `alt` | |
| | | | |
| | consider giving `dir_parser` a type | |
| | | |
| = note: cannot satisfy `_: ParseError<&str>` | |
| note: required by a bound in `alt` | |
| --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.0/src/branch/mod.rs:71:28 | |
| | | |
| 71 | pub fn alt<I: Clone, O, E: ParseError<I>, List: Alt<I, O, E>>( | |
| | ^^^^^^^^^^^^^ required by this bound in `alt` | |
| help: consider specifying the type arguments in the function call | |
| | | |
| 26 | let mut dir_parser = alt::<I, O, E, List>(( | |
| | +++++++++++++++++ | |
| For more information about this error, try `rustc --explain E0283`. | |
| error: could not compile `part1` due to previous error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![feature(stdin_forwarders)] | |
| use nom::{ | |
| branch::alt, | |
| bytes::complete::tag, | |
| character::complete::digit1, | |
| combinator::{map_res, value}, | |
| sequence::separated_pair, | |
| }; | |
| use std::io::{self}; | |
| #[derive(Clone, Debug)] | |
| enum Direction { | |
| Forward, | |
| Down, | |
| Up, | |
| } | |
| struct Move { | |
| dir: Direction, | |
| count: i32, | |
| } | |
| fn main() { | |
| let mut dir_parser = alt(( | |
| value(Direction::Forward, tag("forward")), | |
| value(Direction::Down, tag("down")), | |
| value(Direction::Up, tag("up")), | |
| )); | |
| let mut dec_parser = map_res(digit1, |s: &str| Ok(s.parse::<u32>().unwrap())); | |
| let mut move_parser = separated_pair(dir_parser, tag(" "), dec_parser); | |
| let mut moves = io::stdin().lines().map(|l| { | |
| let (rest, parsed) = move_parser(&l.unwrap())?; | |
| Ok(parsed) | |
| }); | |
| println!("Hello, world!"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment