fspoettel / advent-of-code-rust

🎄Starter template for solving Advent of Code in Rust.
MIT License
638 stars 43 forks source link

How to use modules? #41

Closed MLNW closed 11 months ago

MLNW commented 11 months ago

Thanks for the great template! It helps a lot to get started quickly with using Rust for AoC.

I was wondering how to go about introducing modules to split out some of the code for a specific puzzle. E.g. for a puzzle where there is a lot of code for parsing the input into structs I would like to have a dedicated file for that day that handles this.

I tried to add a 03 folder with a input.rs but I wasn't able to include anything from it in my 03.rs. I guess it might be that modules may not have a numeric name. But it feels like a more general issue with the structure of the template.

Another case I could imagine is if I wanted to add some more generic functionality that could be reused by multiple puzzles. That I would like to put into a separate module as well. How would that work?

fspoettel commented 11 months ago

you can use the lib file to factor out shared code.

you can also register further module folders or files in there. see for example the template folder which is a module.

MLNW commented 11 months ago

It sounds so simple but I don't seem to get it right. What I tried is this: https://github.com/MLNW/advent_of_code/compare/trunk...2023-rust-modularize

It does not allow me to reference e.g., Coordinates. Do you know what I'm doing wrong?

fspoettel commented 11 months ago

I'll take a look when I'm home. did you add a use statement for the module where you import it?

MLNW commented 11 months ago

That comment got me the last meters: I had to add a line like this

use advent_of_code::input::input_03::{Coordinate, EnginePart, Symbol};

and mark a whole lot of things pub.

Thanks for the help!