Comments (7)
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.
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.
For solvers, have you considered using Debug
instead of Display
?
from aoc.
For solvers, have you considered using
Debug
instead ofDisplay
?
Display seems to be a nice way to go in order to get an inline message for the error:
from aoc.
Implemented by #8
from aoc.
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.
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)
- Generated binary arguments conflict with Criterion's arguments HOT 5
- Add a `standalone` feature HOT 2
- Allow for leading 0 in mod names HOT 4
- [Suggestion] change output color to work better on windows with vscode HOT 1
- [Bug] Recursion Limit HOT 7
- multiple rlib candidates for `aoc_main` found HOT 2
- Allow use of `-d` for benchmarks HOT 2
- .token file should not be stored in project directory HOT 1
- Doesn't compile on stable 1.65 on the 1st of December 2022 HOT 3
- Add information about this tool in the User-Agent header HOT 1
- Add feature flags for heavy dependancies HOT 1
- Invalid header on 0.5.0 HOT 2
- Bench generators
- Support multiple generators
- Publish to crates.io HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aoc.