1use crate::util::AnyValueId;
23/// Violation of [`ArgMatches`][crate::ArgMatches] assumptions
4#[derive(#[automatically_derived]
#[allow(missing_copy_implementations)]
impl ::core::clone::Clone for MatchesError {
#[inline]
fn clone(&self) -> MatchesError {
match self {
MatchesError::Downcast { actual: __self_0, expected: __self_1 } =>
MatchesError::Downcast {
actual: ::core::clone::Clone::clone(__self_0),
expected: ::core::clone::Clone::clone(__self_1),
},
MatchesError::UnknownArgument {} =>
MatchesError::UnknownArgument {},
}
}
}Clone, #[automatically_derived]
#[allow(missing_copy_implementations)]
impl ::core::fmt::Debug for MatchesError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
MatchesError::Downcast { actual: __self_0, expected: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Downcast", "actual", __self_0, "expected", &__self_1),
MatchesError::UnknownArgument {} =>
::core::fmt::Formatter::write_str(f, "UnknownArgument"),
}
}
}Debug)]
5#[allow(missing_copy_implementations)] // We might add non-Copy types in the future
6#[non_exhaustive]
7pub enum MatchesError {
8/// Failed to downcast `AnyValue` to the specified type
9#[non_exhaustive]
10Downcast {
11/// Type for value stored in [`ArgMatches`][crate::ArgMatches]
12actual: AnyValueId,
13/// The target type to downcast to
14expected: AnyValueId,
15 },
16/// Argument not defined in [`Command`][crate::Command]
17#[non_exhaustive]
18UnknownArgument {
19// Missing `id` but blocked on a public id type which will hopefully come with `unstable-v4`
20},
21}
2223impl MatchesError {
24#[cfg_attr(debug_assertions, track_caller)]
25pub(crate) fn unwrap<T>(id: &str, r: Result<T, MatchesError>) -> T {
26let err = match r {
27Ok(t) => {
28return t;
29 }
30Err(err) => err,
31 };
32{
::core::panicking::panic_fmt(format_args!("Mismatch between definition and access of `{0}`. {1}",
id, err));
}panic!("Mismatch between definition and access of `{id}`. {err}",)33 }
34}
3536impl std::error::Errorfor MatchesError {}
3738impl std::fmt::Displayfor MatchesError {
39fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40match self {
41Self::Downcast { actual, expected } => {
42f.write_fmt(format_args!("Could not downcast to {0:?}, need to downcast to {1:?}\n",
expected, actual))writeln!(
43f,
44"Could not downcast to {expected:?}, need to downcast to {actual:?}"
45)46 }
47Self::UnknownArgument {} => {
48f.write_fmt(format_args!("Unknown argument or group id. Make sure you are using the argument id and not the short or long flags\n"))writeln!(
49f,
50"Unknown argument or group id. Make sure you are using the argument id and not the short or long flags"
51)52 }
53 }
54 }
55}
5657#[test]
58fn check_auto_traits() {
59static_assertions::assert_impl_all!(
60 MatchesError: Send,
61 Sync,
62 std::panic::RefUnwindSafe,
63 std::panic::UnwindSafe,
64 Unpin
65 );
66}