diff --git a/xmlity/src/types/infallible.rs b/xmlity/src/types/infallible.rs new file mode 100644 index 0000000..bf06d13 --- /dev/null +++ b/xmlity/src/types/infallible.rs @@ -0,0 +1,51 @@ +use std::convert::Infallible; + +impl crate::de::Error for Infallible { + fn custom(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(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(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}"); + } +} diff --git a/xmlity/src/types/mod.rs b/xmlity/src/types/mod.rs index 8e4121b..3965ca8 100644 --- a/xmlity/src/types/mod.rs +++ b/xmlity/src/types/mod.rs @@ -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;