Coder Social home page Coder Social logo

Comments (7)

remi-dupre avatar remi-dupre commented on September 28, 2024 1

Hi @Silver-Golden!

You'd probably want to tell aoc-main to unwrap the value by suffixing your solutions returning and Option with ? (cf the example). I should probably add a line or two about that in the README ^^

It also makes me wonder how I could allow for something more general than Display as results but still keep a pretty output 🤔

EDIT: I now understand that this last one was the exact suggestion from @WhoisDavid, however I think Debug may be quite ugly in some cases (such as String which would be quoted), maybe the easiest way to go would be to have a special trait which would decide whether Display or Debug would be preferred.

from aoc.

remi-dupre avatar remi-dupre commented on September 28, 2024
macro_rules! test {
    (
        year $year: expr;
        $( $day: ident $( : $generator: ident )? => $( $solution: ident $( ? )? ),+ );+
        $( ; )?
    ) => {};
}

test! {
    year 2020;
    day1 : generator => part1?, part2;
}

This appears to work fine, I suppose suffixing with ? could be a nice syntax :)

from aoc.

WhoisDavid avatar WhoisDavid commented on September 28, 2024

For solvers, have you considered using Debug instead of Display?

from aoc.

remi-dupre avatar remi-dupre commented on September 28, 2024

For solvers, have you considered using Debug instead of Display?

Display seems to be a nice way to go in order to get an inline message for the error:

Screenshot_2020-12-09_20-40-15

from aoc.

remi-dupre avatar remi-dupre commented on September 28, 2024

Implemented by #8

from aoc.

Silver-Golden avatar Silver-Golden commented on September 28, 2024

Setting up aoc-main for last years aoc and trying to run/compile I get this:

   Compiling aoc-2019 v0.1.0 (C:\Dev\WebStorm\Advent of Code\2019)
error[E0277]: `std::option::Option<i32>` doesn't implement `std::fmt::Display`
  --> src\main.rs:6:1
   |
6  | / aoc_main::main! {
7  | |     year 2019;
8  | |     day01 : input_generator => solve_part1, solve_part2;
9  | |     day02 : input_generator => solve_part1, solve_part2;
10 | |     day03 : input_generator => solve_part1, solve_part2;
11 | |     day04 : input_generator => solve_part1, solve_part2;
12 | | }
   | |_^ `std::option::Option<i32>` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `std::option::Option<i32>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: required by `std::fmt::Display::fmt`
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

my cargo.toml is like this:

[dependencies]
aoc-main = { git = "https://github.com/remi-dupre/aoc.git", branch = "main" }

It is a fresh install so it aught to be getting the latest changes, including #8

from aoc.

swlody avatar swlody commented on September 28, 2024

I agree that it would be nice to at least have the option to format using Debug instead of Display. Using Display makes it impossible to return tuples for example, which I found necessary for this year's day 9, meaning I needed to manually create a new struct and implement display for it to get everything working:

pub struct Answer(u64, u64);

use std::fmt;
impl fmt::Display for Answer {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Part 1: {}, Part 2: {}", self.0, self.1)
    }
}

pub fn solve_both_parts(input: &[u64]) -> Answer {
    let part1_result = solve_part1_with_preamble_length(input, 25);
    let part2_result = solve_part2_from_part1(input, part1_result);
    Answer(part1_result, part2_result)
}

vs. just:

pub fn solve_both_parts(input: &[u64]) -> (u64, u64) {
    let part1_result = solve_part1_with_preamble_length(input, 25);
    let part2_result = solve_part2_from_part1(input, part1_result);
    (part1_result, part2_result)
}

from aoc.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.