Skip to content

Commit ba4030e

Browse files
committed
derive Error for PrintfError
1 parent 07f46c2 commit ba4030e

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

COPYING

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2021 Thomas Jollans
1+
Copyright (c) 2021-2024 Thomas Jollans
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ categories = ["template-engine", "wasm"]
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15+
thiserror = "1.0.57"
1516

1617
[dev-dependencies]
1718
libc = "0.2"

src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@
2020
//! The types of the arguments are checked at runtime.
2121
//!
2222
23+
use thiserror::Error;
24+
2325
mod format;
2426
pub mod parser;
2527

2628
pub use format::Printf;
27-
2829
use parser::{parse_format_string, ConversionType, FormatElement, NumericParam};
2930

3031
/// Error type
31-
#[derive(Debug, Clone, Copy)]
32+
#[derive(Debug, Clone, Copy, Error)]
3233
pub enum PrintfError {
3334
/// Error parsing the format string
35+
#[error("Error parsing the format string")]
3436
ParseError,
3537
/// Incorrect type passed as an argument
38+
#[error("Incorrect type passed as an argument")]
3639
WrongType,
3740
/// Too many arguments passed
41+
#[error("Too many arguments passed")]
3842
TooManyArgs,
3943
/// Too few arguments passed
44+
#[error("Too few arguments passed")]
4045
NotEnoughArgs,
4146
/// Other error (should never happen)
47+
#[error("Other error (should never happen)")]
4248
Unknown,
4349
}
4450

src/parser.rs

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pub enum ConversionType {
7676
PercentSign,
7777
}
7878

79-
8079
/// Parses a string to a vector of [FormatElement]
8180
///
8281
/// Takes a printf-style format string `fmt`

0 commit comments

Comments
 (0)