Skip to content

Commit bc41196

Browse files
authored
feat(core): Infallible error types. (#122)
* feat(core): Infallible error types. * `cargo clippy`
1 parent 8fa0f4c commit bc41196

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

xmlity/src/types/infallible.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use std::convert::Infallible;
2+
3+
impl crate::de::Error for Infallible {
4+
fn custom<T>(msg: T) -> Self
5+
where
6+
T: std::fmt::Display,
7+
{
8+
panic!("Infallible error: {msg}");
9+
}
10+
11+
fn wrong_name(name: &crate::ExpandedName<'_>, expected: &crate::ExpandedName<'_>) -> Self {
12+
panic!("Infallible error: wrong name \"{name}\", expected \"{expected}\"");
13+
}
14+
15+
fn unexpected_visit<T>(unexpected: crate::de::Unexpected, _expected: &T) -> Self {
16+
panic!("Infallible error: unexpected visit of {unexpected}");
17+
}
18+
19+
fn missing_field(field: &str) -> Self {
20+
panic!("Infallible error: missing field {field}");
21+
}
22+
23+
fn no_possible_variant(ident: &str) -> Self {
24+
panic!("Infallible error: no possible variant {ident}");
25+
}
26+
27+
fn missing_data() -> Self {
28+
panic!("Infallible error: missing data");
29+
}
30+
31+
fn unknown_child() -> Self {
32+
panic!("Infallible error: unknown child");
33+
}
34+
35+
fn invalid_string() -> Self {
36+
panic!("Infallible error: invalid string");
37+
}
38+
}
39+
40+
impl crate::ser::Error for Infallible {
41+
fn custom<T>(msg: T) -> Self
42+
where
43+
T: std::fmt::Display,
44+
{
45+
panic!("Infallible error: {msg}");
46+
}
47+
48+
fn unexpected_serialize(unexpected: crate::ser::Unexpected) -> Self {
49+
panic!("Infallible error: unexpected serialize of {unexpected}");
50+
}
51+
}

xmlity/src/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! It also contains some visitors for the types which can be reused, including [`iterator::IteratorVisitor`].
44
55
pub mod common;
6+
mod infallible;
67
pub mod iterator;
78
mod primitive;
89
mod smart;

0 commit comments

Comments
 (0)