Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions xmlity/src/types/infallible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::convert::Infallible;

impl crate::de::Error for Infallible {
fn custom<T>(msg: T) -> Self
where
T: std::fmt::Display,
{
panic!("Infallible error: {msg}");
}

fn wrong_name(name: &crate::ExpandedName<'_>, expected: &crate::ExpandedName<'_>) -> Self {
panic!("Infallible error: wrong name \"{name}\", expected \"{expected}\"");
}

fn unexpected_visit<T>(unexpected: crate::de::Unexpected, _expected: &T) -> Self {
panic!("Infallible error: unexpected visit of {unexpected}");
}

fn missing_field(field: &str) -> Self {
panic!("Infallible error: missing field {field}");
}

fn no_possible_variant(ident: &str) -> Self {
panic!("Infallible error: no possible variant {ident}");
}

fn missing_data() -> Self {
panic!("Infallible error: missing data");
}

fn unknown_child() -> Self {
panic!("Infallible error: unknown child");
}

fn invalid_string() -> Self {
panic!("Infallible error: invalid string");
}
}

impl crate::ser::Error for Infallible {
fn custom<T>(msg: T) -> Self
where
T: std::fmt::Display,
{
panic!("Infallible error: {msg}");
}

fn unexpected_serialize(unexpected: crate::ser::Unexpected) -> Self {
panic!("Infallible error: unexpected serialize of {unexpected}");
}
}
1 change: 1 addition & 0 deletions xmlity/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! It also contains some visitors for the types which can be reused, including [`iterator::IteratorVisitor`].

pub mod common;
mod infallible;
pub mod iterator;
mod primitive;
mod smart;
Expand Down