1use crate::fmt;
2use crate::input::Input;
3
4use super::{
5 Context, ExpectedLength, ExpectedValid, ExpectedValue, RetryRequirement, ToRetryRequirement,
6 WithContext,
7};
8
9#[derive(Debug, PartialEq)]
32#[must_use = "error must be handled"]
33pub struct Fatal;
34
35impl fmt::DisplayBase for Fatal {
36 fn fmt(&self, w: &mut dyn fmt::Write) -> fmt::Result {
37 w.write_str("invalid input")
38 }
39}
40
41impl fmt::Display for Fatal {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 fmt::DisplayBase::fmt(self, f)
44 }
45}
46
47impl<'i> WithContext<'i> for Fatal {
48 const PASSTHROUGH: bool = true;
49
50 #[inline(always)]
51 fn with_input(self, _input: impl Input<'i>) -> Self {
52 self
53 }
54
55 #[inline(always)]
56 fn with_context(self, _context: impl Context) -> Self {
57 self
58 }
59}
60
61impl ToRetryRequirement for Fatal {
62 fn to_retry_requirement(&self) -> Option<RetryRequirement> {
63 None
64 }
65
66 fn is_fatal(&self) -> bool {
67 true
68 }
69}
70
71impl<'i> From<ExpectedValue<'i>> for Fatal {
72 fn from(_: ExpectedValue<'i>) -> Self {
73 Self
74 }
75}
76
77impl<'i> From<ExpectedLength<'i>> for Fatal {
78 fn from(_: ExpectedLength<'i>) -> Self {
79 Self
80 }
81}
82
83impl<'i> From<ExpectedValid<'i>> for Fatal {
84 fn from(_: ExpectedValid<'i>) -> Self {
85 Self
86 }
87}