updating templates to use error_stack and thiserror
This commit is contained in:
@@ -7,11 +7,13 @@ repository.workspace = true
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nom = { workspace = true }
|
nom.workspace = true
|
||||||
itertools = {workspace = true }
|
itertools.workspace = true
|
||||||
error-stack = {workspace = true}
|
log.workspace = true
|
||||||
|
error-stack.workspace = true
|
||||||
|
thiserror.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test-log = {workspace=true}
|
test-log.workspace = true
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,22 @@
|
|||||||
use {{ crate_name }}::part1;
|
use {{ crate_name }}::part1;
|
||||||
use {{ crate_name }}::part2;
|
use {{ crate_name }}::part2;
|
||||||
|
|
||||||
fn main() {
|
use error_stack::{Result, ResultExt};
|
||||||
let input = include_str!("./input.txt");
|
use thiserror::Error;
|
||||||
let part1_result = part1(input).expect("part 1 should have no error");
|
|
||||||
println!("part 1: {part1_result}");
|
#[derive(Debug, Error)]
|
||||||
let part2_result = part2(input).expect("part 2 should have no error");
|
enum {{ project-name | upper_camel_case }}Error {
|
||||||
println!("part 2: {part2_result}");
|
#[error("Part 1 failed")]
|
||||||
|
Part1Error,
|
||||||
|
#[error("Part 2 failed")]
|
||||||
|
Part2Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), {{ project-name | upper_camel_case }}Error> {
|
||||||
|
let input = include_str!("./input.txt");
|
||||||
|
let part1_result = part1(input).change_context({{ project-name | upper_camel_case }}Error::Part1Error)?;
|
||||||
|
println!("part 1: {part1_result}");
|
||||||
|
let part2_result = part2(input).change_context({{ project-name | upper_camel_case }}Error::Part2Error)?;
|
||||||
|
println!("part 2: {part2_result}");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fmt::Display;
|
use error_stack::Result;
|
||||||
|
use thiserror::Error;
|
||||||
use error_stack::{Context, Result};
|
|
||||||
|
|
||||||
// {{project-name}}
|
// {{project-name}}
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub struct {{project-name|upper_camel_case}}Part1Error;
|
pub enum {{ project-name | upper_camel_case }}Part1Error{
|
||||||
|
#[error("Problem parsing {{ project-name | title_case }}")]
|
||||||
impl Context for {{project-name|upper_camel_case}}Part1Error {}
|
ParseError,
|
||||||
|
|
||||||
impl Display for {{project-name|upper_camel_case}}Part1Error {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "day 1 part 1 error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part1 (_input: &str) -> Result<String, {{ project-name | upper_camel_case }}Part1Error> {
|
pub fn part1 (_input: &str) -> Result<String, {{ project-name | upper_camel_case }}Part1Error> {
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::fmt::Display;
|
use error_stack::Result;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use error_stack::{Context, Result};
|
// {{project-name}}
|
||||||
|
#[derive(Debug, Error)]
|
||||||
#[derive(Debug)]
|
pub enum {{ project-name | upper_camel_case }}Part2Error{
|
||||||
pub struct {{ project-name | upper_camel_case }}Part2Error;
|
#[error("Problem parsing {{project-name | title_case }}")]
|
||||||
|
ParseError,
|
||||||
impl Context for {{ project-name | upper_camel_case }}Part2Error {}
|
|
||||||
|
|
||||||
impl Display for {{ project-name | upper_camel_case }}Part2Error {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "day 1 part 1 error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part2 (_input: &str) -> Result<String, {{ project-name | upper_camel_case }}Part2Error> {
|
pub fn part2 (_input: &str) -> Result<String, {{ project-name | upper_camel_case }}Part2Error> {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ num-traits = "0.2.17"
|
|||||||
rustworkx-core = "0.13.2"
|
rustworkx-core = "0.13.2"
|
||||||
pathfinding = "4.8.0"
|
pathfinding = "4.8.0"
|
||||||
test-log = {version="0.2.14", features=["default", "unstable"]}
|
test-log = {version="0.2.14", features=["default", "unstable"]}
|
||||||
|
thiserror = "1.0.56"
|
||||||
|
|
||||||
|
|
||||||
[profile.dhat]
|
[profile.dhat]
|
||||||
|
|||||||
Reference in New Issue
Block a user