1 /// Violation of [`ArgMatches`][crate::ArgMatches] assumptions
2 #[derive(Clone, Debug)]
3 #[allow(missing_copy_implementations)] // We might add non-Copy types in the future
5 pub enum MatchesError
{
6 /// Failed to downcast `AnyValue` to the specified type
9 /// Type for value stored in [`ArgMatches`][crate::ArgMatches]
10 actual
: super::AnyValueId
,
11 /// The target type to downcast to
12 expected
: super::AnyValueId
,
14 /// Argument not defined in [`Command`][crate::Command]
17 // Missing `id` but blocked on a public id type which will hopefully come with `unstable-v4`
22 #[cfg_attr(debug_assertions, track_caller)]
23 pub(crate) fn unwrap
<T
>(id
: &str, r
: Result
<T
, MatchesError
>) -> T
{
31 "Mismatch between definition and access of `{}`. {}",
37 impl std
::error
::Error
for MatchesError {}
39 impl std
::fmt
::Display
for MatchesError
{
40 fn fmt(&self, f
: &mut std
::fmt
::Formatter
) -> std
::fmt
::Result
{
42 Self::Downcast { actual, expected }
=> {
45 "Could not downcast to {:?}, need to downcast to {:?}",
49 Self::UnknownArgument {}
=> {
50 writeln
!(f
, "Unknown argument or group id. Make sure you are using the argument id and not the short or long flags")
57 fn check_auto_traits() {
58 static_assertions
::assert_impl_all
!(
61 std
::panic
::RefUnwindSafe
,
62 std
::panic
::UnwindSafe
,