aocsol/
lib.rs

1//! A crate that holds solutions to [Advent of Code](https://adventofcode.com)(AoC) puzzles.
2//! The solutions are implemented in async rust, thus need an async runtime such as [`tokio`](https://docs.rs/tokio/1.28.1/tokio).
3//!
4//! # Feature-flags
5//! By default, [`Puzzl`] and [`Solve`] traits are provided.
6//!
7//! To generate solvers for a puzzle using [`solver`],
8//! add `solvers` [feature flag] in Cargo.toml
9//!
10//! If you wish to implement your own solver, and only require some
11//! useful utilities, add `toolcase` [feature flag] in Cargo.toml
12//!
13//! # Examples
14//!
15//! Two traits [`Puzzl`] and [`Solve`] are provided to interface with the
16//! solvers.
17//!
18//! ```no_run
19//! use std::{error, sync::Arc};
20//!
21//! use aocsol::{puzzle::Puzzl, solver};
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), Box<dyn error::Error + Send + Sync>> {
25//!     let data = "1000\n2000\n\n4000\n\n5000\n6000\n\n7000\n9000";
26//!     let puzzle = AocPuzzle(Arc::from(data));
27//!     let solver = solver::solver(puzzle)?;   // solver generated
28//!
29//!     let answer_part_one: u32 = solver.part_one().await?.to_string().parse()?;
30//!     let answer_part_two: u32 = solver.part_two().await?.to_string().parse()?;
31//!
32//!     assert_eq!(16000, answer_part_one);
33//!     assert_eq!(31000, answer_part_two);
34//!
35//!     Ok(())
36//! }
37//!
38//! // Sturct to hold data.
39//! struct AocPuzzle(Arc<str>);
40//!
41//! // Implement Puzzl<InputType = Arc<str>> to generate solver using aocsol::solver::solver().
42//! impl<'input> Puzzl for AocPuzzle {
43//!     type InputType = Arc<str>;
44//!
45//!     fn year(&self) -> u32 {
46//!         2022
47//!     }
48//!
49//!     fn day(&self) -> u32 {
50//!         1
51//!     }
52//!
53//!     fn data(&self) -> Self::InputType {
54//!         Arc::clone(&self.0)
55//!     }
56//! }
57//! ```
58//!
59//! [`Puzzl`]: crate::puzzle::Puzzl
60//! [`Solve`]: crate::puzzle::Solve
61//! [feature flag]: https://doc.rust-lang.org/cargo/reference/features.html#the-features-section
62
63pub mod error;
64pub mod puzzle;
65
66#[cfg(feature = "toolcase")]
67pub mod toolcase;
68
69#[cfg(feature = "solvers")]
70pub mod solver;
71
72pub(crate) mod macros;
73
74#[cfg(all(test, feature = "solvers"))]
75#[macro_use]
76extern crate lazy_static;