New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha support for `Result`s #12

Closed
gobanos opened this Issue Dec 2, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@gobanos
Owner

gobanos commented Dec 2, 2018

Generators & Runners now support Results in return position !
I need some feedback before release, so please install alpha & comment on this issue.

Setup

In your Cargo.toml:

aoc-runner = "0.2.0-alpha1"
aoc-runner-derive = "0.2.0-alpha1"

In your terminal:
$ cargo install cargo-aoc --force --version 0.2.0-alpha1

Examples

#[aoc_generator(day1)]
fn parse_input(input: &str) -> Result<Vec<i32>, ParseIntError> {
    input
        .lines()
        .map(|l| l.parse())
        .collect()
}

#[aoc(day1, part1)]
fn part1(freqs: &[i32]) -> i32 {
    freqs.iter().sum()
}

Known limitation

By far, the biggest limitation is that I need the return type to be called Result (it still can be prefixed with a path), with at least a template parameter.
So these wont work :

type MyRes = Result<Vec<i32>, ParseIntError>;

#[aoc_generator(day1)]
fn parse_input(input: &str) -> MyRes {
    ...
}
type Result = std::result::Result<Vec<i32>, ParseIntError>;

#[aoc_generator(day1)]
fn parse_input(input: &str) -> MyRes {
    ...
}
@uberjay

This comment has been minimized.

uberjay commented Dec 2, 2018

Oh wow, I was just wishing cargo-aoc has this feature. I'll give it a try right now!

@nugend

This comment has been minimized.

nugend commented Dec 2, 2018

Could you also support Options?

@uberjay

This comment has been minimized.

uberjay commented Dec 2, 2018

It's alright! To be honest, It's a little hard to tell how useful it'll be only 2 days in. Something that would be pretty handy in conjunction with this would be a way to feed in alternate input data. I guess I could just use #[test] functions for this!

@gbear605

This comment has been minimized.

gbear605 commented Dec 3, 2018

It's working fine for me!

@gobanos

This comment has been minimized.

Owner

gobanos commented Dec 6, 2018

cargo-aoc 0.2.0, with support for Result & Option is out : https://github.com/gobanos/cargo-aoc/releases/tag/0.2.0

@gobanos gobanos closed this Dec 6, 2018

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