gobanos/cargo-aoc

Can't get minimal example to work

bradydean opened this issue · 3 comments

Not sure if I'm doing something wrong, or if this package is out of date now. I used it back for aoc 2020 and it worked great. Trying on Rust 1.65.0.

use aoc_runner_derive::{aoc_lib, aoc_generator, aoc};

#[aoc_generator(day1)]
fn input_generator(input: &str) -> Vec<u32> {
    vec![42]
}


#[aoc(day1, part1)]
fn part1(input: &[u32]) -> u32 {
    0
}


aoc_lib!{ year = 2021 }
   Compiling aoc-autobuild v0.3.0 (/home/brady/aoc2021/target/aoc/aoc-autobuild)
error[E0308]: mismatched types
  --> src/main.rs:19:35
   |
19 |         match Factory::day1_part1(input_day1.clone()) {
   |               ------------------- ^^^^^^^^^^^^^^^^^^ expected struct `aoc_runner::ArcStr`, found struct `ArcStr`
   |               |
   |               arguments to this function are incorrect
   |
   = note: perhaps two different versions of crate `aoc_runner` are being used?
note: associated function defined here
  --> /home/brady/aoc2021/src/lib.rs:15:1
   |
15 | aoc_lib!{ year = 2021 }
   | ^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the macro `aoc_lib` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
  --> src/main.rs:20:13
   |
19 |         match Factory::day1_part1(input_day1.clone()) {
   |               --------------------------------------- this expression has type `Box<dyn aoc_runner::Runner>`
20 |             Ok(runner) => {
   |             ^^^^^^^^^^ expected struct `Box`, found enum `Result`
   |
   = note: expected struct `Box<dyn aoc_runner::Runner>`
                found enum `Result<_, _>`

error[E0308]: mismatched types
  --> src/main.rs:31:13
   |
19 |         match Factory::day1_part1(input_day1.clone()) {
   |               --------------------------------------- this expression has type `Box<dyn aoc_runner::Runner>`
...
31 |             Err(e) => eprintln!("Day 1 - Part 1 : FAILED while generating :\n{:#?}\n", e)
   |             ^^^^^^ expected struct `Box`, found enum `Result`
   |
   = note: expected struct `Box<dyn aoc_runner::Runner>`
                found enum `Result<_, _>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `aoc-autobuild` due to 3 previous errors

i tried also another return type than usize and got some problem.
try fn part1(input: &[u32]) -> usize

maybe same for input, try

#[aoc_generator(day22)]
fn parse_input(input: &str) -> String {
input.to_string()
}

Hi !
Looks like you have incompatible versions of cargo aoc & aoc-runner.
I've updated the example repository to use the last version.

So the steps to fix that:

  • Make sure you have the last cargo aoc (cargo aoc --version should yield cargo-aoc 0.3.0)
  • Use the last version of aoc-runner & aoc-runner-derive:
aoc-runner = "0.3.0"
aoc-runner-derive = "0.3.0"