Skip to content

Commit

Permalink
Add DuplicateEntry type alias.
Browse files Browse the repository at this point in the history
Impl `Error` for `DuplicateEntry`.
  • Loading branch information
timothee-haudebourg committed Feb 21, 2024
1 parent 19f5e2e commit e4e3da9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "json-syntax"
version = "0.12.1"
version = "0.12.2"
edition = "2021"
authors = ["Timothée Haudebourg <author@haudebourg.net>"]
description = "Strict JSON parsing and mapping library"
Expand Down
11 changes: 11 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,17 @@ where
#[derive(Debug)]
pub struct Duplicate<T>(pub T, pub T);

/// Duplicate entry error.
pub type DuplicateEntry = Duplicate<Entry>;

impl fmt::Display for DuplicateEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "duplicate entry `{}`", self.0.key)
}
}

impl std::error::Error for DuplicateEntry {}

#[cfg(test)]
mod tests {
use crate::BorrowUnordered;
Expand Down

0 comments on commit e4e3da9

Please sign in to comment.