1//! Component range error
23use core::fmt;
45use crate::error;
67/// An error type indicating that a component provided to a method was out of range, causing a
8/// failure.
9// i64 is the narrowest type fitting all use cases. This eliminates the need for a type parameter.
10#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ComponentRange {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ComponentRange", "name", &self.name, "is_conditional",
&&self.is_conditional)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for ComponentRange {
#[inline]
fn clone(&self) -> ComponentRange {
let _: ::core::clone::AssertParamIsClone<&'static str>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ComponentRange { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for ComponentRange {
#[inline]
fn eq(&self, other: &ComponentRange) -> bool {
self.is_conditional == other.is_conditional && self.name == other.name
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ComponentRange {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<&'static str>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for ComponentRange {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.name, state);
::core::hash::Hash::hash(&self.is_conditional, state)
}
}Hash)]
11pub struct ComponentRange {
12/// Name of the component.
13pub(crate) name: &'static str,
14/// Whether an input with the same value could have succeeded if the values of other components
15 /// were different.
16pub(crate) is_conditional: bool,
17}
1819impl ComponentRange {
20/// Create a new `ComponentRange` error that is not conditional.
21#[inline]
22pub(crate) const fn unconditional(name: &'static str) -> Self {
23Self {
24name,
25 is_conditional: false,
26 }
27 }
2829/// Create a new `ComponentRange` error that is conditional.
30#[inline]
31pub(crate) const fn conditional(name: &'static str) -> Self {
32Self {
33name,
34 is_conditional: true,
35 }
36 }
3738/// Obtain the name of the component whose value was out of range.
39#[inline]
40pub const fn name(self) -> &'static str {
41self.name
42 }
4344/// Whether the value's permitted range is conditional, i.e. whether an input with this
45 /// value could have succeeded if the values of other components were different.
46#[inline]
47pub const fn is_conditional(self) -> bool {
48self.is_conditional
49 }
50}
5152impl fmt::Displayfor ComponentRange {
53#[inline]
54fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55f.write_fmt(format_args!("{0} was not in range", self.name))write!(f, "{} was not in range", self.name)56 }
57}
5859impl From<ComponentRange> for crate::Error {
60#[inline]
61fn from(original: ComponentRange) -> Self {
62Self::ComponentRange(original)
63 }
64}
6566impl TryFrom<crate::Error> for ComponentRange {
67type Error = error::DifferentVariant;
6869#[inline]
70fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
71match err {
72crate::Error::ComponentRange(err) => Ok(err),
73_ => Err(error::DifferentVariant),
74 }
75 }
76}
7778/// **This trait implementation is deprecated and will be removed in a future breaking release.**
79#[cfg(feature = "serde")]
80impl serde_core::de::Expected for ComponentRange {
81#[inline]
82fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 f.write_str("an in-range value")
84 }
85}
8687#[cfg(feature = "serde")]
88impl ComponentRange {
89/// Convert the error to a deserialization error.
90#[inline]
91pub(crate) fn into_de_error<E>(self) -> E
92where
93E: serde_core::de::Error,
94 {
95 serde_core::de::Error::custom(format_args!(
96"invalid {}, expected an in-range value",
97self.name
98 ))
99 }
100}
101102impl core::error::Errorfor ComponentRange {}