gobanos / cargo-aoc

437 stars 47 forks source link

aoc_generator(day, part) seems broken #79

Open rbtcollins opened 2 years ago

rbtcollins commented 2 years ago
error: custom attribute panicked
 --> src\day1.rs:9:1
  |
9 | #[aoc_generator(day1, pt1_windows2)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: A generator is already defined: Runner { generator: Some(Generator { name: "generate", out_t: "Vec < u32 >", special_type: None }), solver: None }

error: custom attribute panicked
  --> src\day1.rs:22:1
   |
22 | #[aoc(day1, part1_windows2)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: runners must have a defined part: "Failed to parse part: part1_windows2"

error: could not compile `aoc-2021` due to 2 previous errors
An error occurs : cargo build failed with code 101
#[aoc_generator(day1)]
fn generate(input: &str) -> Vec<u32> {
    input.lines().flat_map(|s| s.parse()).collect()
}

#[aoc_generator(day1, pt1_windows2)]
fn generate(input: &str) -> Vec<u32> {
    input.lines().flat_map(|s| s.parse()).collect()
}

#[aoc(day1, part1)]
fn solve_part1(input: &[u32]) -> usize {
    input
        .windows(2)
        .filter(|window| window[0] < window[1])
        .count()
}

#[aoc(day1, part1, windows2)]
fn solve_part1_windows2(input: &[u32]) -> usize {
    input
        .windows(2)
        .filter(|window| window[0] < window[1])
        .count()
}
rbtcollins commented 2 years ago

I realise I had a little confusion in the same - edited; but basically its not clear to me how to use different generators... or perhaps they cannot be used to specialise different implementations of a single part?

uniqueNullptr2 commented 2 years ago

as far as I can see generator works analogous to aoc

[aoc_generator(day1)] -> used for all solvers of day 1

[aoc_generator(day1, part2)] -> used for all part 2 solvers of day 1

[aoc_generator(day1, part2, something)] -> used for the day1 part2 solution marked "something"

ithinuel commented 2 years ago

The first error is an issue with proc macros & rust-analyzer's macro expansion's feature. You can disable that error by setting "rust-analyzer.procMacro.enable": false in your config.

The second error is as @uniqueNullptr2 described.

Edit: Nevermind I see it's already tracked here: https://github.com/gobanos/cargo-aoc/issues/75