1 // Std 2 use std::{ 3 ffi::{OsStr, OsString}, 4 fmt as std_fmt, 5 rc::Rc, 6 }; 7 8 // Internal 9 use crate::{ 10 args::settings::ArgSettings, 11 map::{self, VecMap}, 12 INTERNAL_ERROR_MSG, 13 }; 14 15 #[doc(hidden)] 16 pub trait AnyArg<'n, 'e>: std_fmt::Display { name(&self) -> &'n str17 fn name(&self) -> &'n str; overrides(&self) -> Option<&[&'e str]>18 fn overrides(&self) -> Option<&[&'e str]>; aliases(&self) -> Option<Vec<&'e str>>19 fn aliases(&self) -> Option<Vec<&'e str>>; requires(&self) -> Option<&[(Option<&'e str>, &'n str)]>20 fn requires(&self) -> Option<&[(Option<&'e str>, &'n str)]>; blacklist(&self) -> Option<&[&'e str]>21 fn blacklist(&self) -> Option<&[&'e str]>; required_unless(&self) -> Option<&[&'e str]>22 fn required_unless(&self) -> Option<&[&'e str]>; is_set(&self, setting: ArgSettings) -> bool23 fn is_set(&self, setting: ArgSettings) -> bool; set(&mut self, setting: ArgSettings)24 fn set(&mut self, setting: ArgSettings); has_switch(&self) -> bool25 fn has_switch(&self) -> bool; max_vals(&self) -> Option<u64>26 fn max_vals(&self) -> Option<u64>; min_vals(&self) -> Option<u64>27 fn min_vals(&self) -> Option<u64>; num_vals(&self) -> Option<u64>28 fn num_vals(&self) -> Option<u64>; possible_vals(&self) -> Option<&[&'e str]>29 fn possible_vals(&self) -> Option<&[&'e str]>; 30 #[cfg_attr(feature = "cargo-clippy", allow(clippy::type_complexity))] validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>31 fn validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>; 32 #[cfg_attr(feature = "cargo-clippy", allow(clippy::type_complexity))] validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>>33 fn validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>>; short(&self) -> Option<char>34 fn short(&self) -> Option<char>; long(&self) -> Option<&'e str>35 fn long(&self) -> Option<&'e str>; val_delim(&self) -> Option<char>36 fn val_delim(&self) -> Option<char>; takes_value(&self) -> bool37 fn takes_value(&self) -> bool; val_names(&self) -> Option<&VecMap<&'e str>>38 fn val_names(&self) -> Option<&VecMap<&'e str>>; help(&self) -> Option<&'e str>39 fn help(&self) -> Option<&'e str>; long_help(&self) -> Option<&'e str>40 fn long_help(&self) -> Option<&'e str>; default_val(&self) -> Option<&'e OsStr>41 fn default_val(&self) -> Option<&'e OsStr>; default_vals_ifs(&self) -> Option<map::Values<(&'n str, Option<&'e OsStr>, &'e OsStr)>>42 fn default_vals_ifs(&self) -> Option<map::Values<(&'n str, Option<&'e OsStr>, &'e OsStr)>>; env<'s>(&'s self) -> Option<(&'n OsStr, Option<&'s OsString>)>43 fn env<'s>(&'s self) -> Option<(&'n OsStr, Option<&'s OsString>)>; longest_filter(&self) -> bool44 fn longest_filter(&self) -> bool; val_terminator(&self) -> Option<&'e str>45 fn val_terminator(&self) -> Option<&'e str>; 46 } 47 48 pub trait DispOrder { disp_ord(&self) -> usize49 fn disp_ord(&self) -> usize; 50 } 51 52 impl<'n, 'e, 'z, T: ?Sized> AnyArg<'n, 'e> for &'z T 53 where 54 T: AnyArg<'n, 'e> + 'z, 55 { name(&self) -> &'n str56 fn name(&self) -> &'n str { 57 (*self).name() 58 } overrides(&self) -> Option<&[&'e str]>59 fn overrides(&self) -> Option<&[&'e str]> { 60 (*self).overrides() 61 } aliases(&self) -> Option<Vec<&'e str>>62 fn aliases(&self) -> Option<Vec<&'e str>> { 63 (*self).aliases() 64 } requires(&self) -> Option<&[(Option<&'e str>, &'n str)]>65 fn requires(&self) -> Option<&[(Option<&'e str>, &'n str)]> { 66 (*self).requires() 67 } blacklist(&self) -> Option<&[&'e str]>68 fn blacklist(&self) -> Option<&[&'e str]> { 69 (*self).blacklist() 70 } required_unless(&self) -> Option<&[&'e str]>71 fn required_unless(&self) -> Option<&[&'e str]> { 72 (*self).required_unless() 73 } is_set(&self, a: ArgSettings) -> bool74 fn is_set(&self, a: ArgSettings) -> bool { 75 (*self).is_set(a) 76 } set(&mut self, _: ArgSettings)77 fn set(&mut self, _: ArgSettings) { 78 panic!("{}", INTERNAL_ERROR_MSG) 79 } has_switch(&self) -> bool80 fn has_switch(&self) -> bool { 81 (*self).has_switch() 82 } max_vals(&self) -> Option<u64>83 fn max_vals(&self) -> Option<u64> { 84 (*self).max_vals() 85 } min_vals(&self) -> Option<u64>86 fn min_vals(&self) -> Option<u64> { 87 (*self).min_vals() 88 } num_vals(&self) -> Option<u64>89 fn num_vals(&self) -> Option<u64> { 90 (*self).num_vals() 91 } possible_vals(&self) -> Option<&[&'e str]>92 fn possible_vals(&self) -> Option<&[&'e str]> { 93 (*self).possible_vals() 94 } 95 #[cfg_attr(feature = "cargo-clippy", allow(clippy::type_complexity))] validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>96 fn validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>> { 97 (*self).validator() 98 } 99 #[cfg_attr(feature = "cargo-clippy", allow(clippy::type_complexity))] validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>>100 fn validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>> { 101 (*self).validator_os() 102 } short(&self) -> Option<char>103 fn short(&self) -> Option<char> { 104 (*self).short() 105 } long(&self) -> Option<&'e str>106 fn long(&self) -> Option<&'e str> { 107 (*self).long() 108 } val_delim(&self) -> Option<char>109 fn val_delim(&self) -> Option<char> { 110 (*self).val_delim() 111 } takes_value(&self) -> bool112 fn takes_value(&self) -> bool { 113 (*self).takes_value() 114 } val_names(&self) -> Option<&VecMap<&'e str>>115 fn val_names(&self) -> Option<&VecMap<&'e str>> { 116 (*self).val_names() 117 } help(&self) -> Option<&'e str>118 fn help(&self) -> Option<&'e str> { 119 (*self).help() 120 } long_help(&self) -> Option<&'e str>121 fn long_help(&self) -> Option<&'e str> { 122 (*self).long_help() 123 } default_val(&self) -> Option<&'e OsStr>124 fn default_val(&self) -> Option<&'e OsStr> { 125 (*self).default_val() 126 } default_vals_ifs(&self) -> Option<map::Values<(&'n str, Option<&'e OsStr>, &'e OsStr)>>127 fn default_vals_ifs(&self) -> Option<map::Values<(&'n str, Option<&'e OsStr>, &'e OsStr)>> { 128 (*self).default_vals_ifs() 129 } env<'s>(&'s self) -> Option<(&'n OsStr, Option<&'s OsString>)>130 fn env<'s>(&'s self) -> Option<(&'n OsStr, Option<&'s OsString>)> { 131 (*self).env() 132 } longest_filter(&self) -> bool133 fn longest_filter(&self) -> bool { 134 (*self).longest_filter() 135 } val_terminator(&self) -> Option<&'e str>136 fn val_terminator(&self) -> Option<&'e str> { 137 (*self).val_terminator() 138 } 139 } 140