1 // Std 2 use std::ffi::{OsStr, OsString}; 3 use std::fmt as std_fmt; 4 use std::rc::Rc; 5 6 // Internal 7 use args::settings::ArgSettings; 8 use map::{self, VecMap}; 9 use INTERNAL_ERROR_MSG; 10 11 #[doc(hidden)] 12 pub trait AnyArg<'n, 'e>: std_fmt::Display { name(&self) -> &'n str13 fn name(&self) -> &'n str; overrides(&self) -> Option<&[&'e str]>14 fn overrides(&self) -> Option<&[&'e str]>; aliases(&self) -> Option<Vec<&'e str>>15 fn aliases(&self) -> Option<Vec<&'e str>>; requires(&self) -> Option<&[(Option<&'e str>, &'n str)]>16 fn requires(&self) -> Option<&[(Option<&'e str>, &'n str)]>; blacklist(&self) -> Option<&[&'e str]>17 fn blacklist(&self) -> Option<&[&'e str]>; required_unless(&self) -> Option<&[&'e str]>18 fn required_unless(&self) -> Option<&[&'e str]>; is_set(&self, ArgSettings) -> bool19 fn is_set(&self, ArgSettings) -> bool; set(&mut self, ArgSettings)20 fn set(&mut self, ArgSettings); has_switch(&self) -> bool21 fn has_switch(&self) -> bool; max_vals(&self) -> Option<u64>22 fn max_vals(&self) -> Option<u64>; min_vals(&self) -> Option<u64>23 fn min_vals(&self) -> Option<u64>; num_vals(&self) -> Option<u64>24 fn num_vals(&self) -> Option<u64>; possible_vals(&self) -> Option<&[&'e str]>25 fn possible_vals(&self) -> Option<&[&'e str]>; validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>26 fn validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>; validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>>27 fn validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>>; short(&self) -> Option<char>28 fn short(&self) -> Option<char>; long(&self) -> Option<&'e str>29 fn long(&self) -> Option<&'e str>; val_delim(&self) -> Option<char>30 fn val_delim(&self) -> Option<char>; takes_value(&self) -> bool31 fn takes_value(&self) -> bool; val_names(&self) -> Option<&VecMap<&'e str>>32 fn val_names(&self) -> Option<&VecMap<&'e str>>; help(&self) -> Option<&'e str>33 fn help(&self) -> Option<&'e str>; long_help(&self) -> Option<&'e str>34 fn long_help(&self) -> Option<&'e str>; default_val(&self) -> Option<&'e OsStr>35 fn default_val(&self) -> Option<&'e OsStr>; default_vals_ifs(&self) -> Option<map::Values<(&'n str, Option<&'e OsStr>, &'e OsStr)>>36 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>)>37 fn env<'s>(&'s self) -> Option<(&'n OsStr, Option<&'s OsString>)>; longest_filter(&self) -> bool38 fn longest_filter(&self) -> bool; val_terminator(&self) -> Option<&'e str>39 fn val_terminator(&self) -> Option<&'e str>; 40 } 41 42 pub trait DispOrder { disp_ord(&self) -> usize43 fn disp_ord(&self) -> usize; 44 } 45 46 impl<'n, 'e, 'z, T: ?Sized> AnyArg<'n, 'e> for &'z T 47 where 48 T: AnyArg<'n, 'e> + 'z, 49 { name(&self) -> &'n str50 fn name(&self) -> &'n str { 51 (*self).name() 52 } overrides(&self) -> Option<&[&'e str]>53 fn overrides(&self) -> Option<&[&'e str]> { 54 (*self).overrides() 55 } aliases(&self) -> Option<Vec<&'e str>>56 fn aliases(&self) -> Option<Vec<&'e str>> { 57 (*self).aliases() 58 } requires(&self) -> Option<&[(Option<&'e str>, &'n str)]>59 fn requires(&self) -> Option<&[(Option<&'e str>, &'n str)]> { 60 (*self).requires() 61 } blacklist(&self) -> Option<&[&'e str]>62 fn blacklist(&self) -> Option<&[&'e str]> { 63 (*self).blacklist() 64 } required_unless(&self) -> Option<&[&'e str]>65 fn required_unless(&self) -> Option<&[&'e str]> { 66 (*self).required_unless() 67 } is_set(&self, a: ArgSettings) -> bool68 fn is_set(&self, a: ArgSettings) -> bool { 69 (*self).is_set(a) 70 } set(&mut self, _: ArgSettings)71 fn set(&mut self, _: ArgSettings) { 72 panic!(INTERNAL_ERROR_MSG) 73 } has_switch(&self) -> bool74 fn has_switch(&self) -> bool { 75 (*self).has_switch() 76 } max_vals(&self) -> Option<u64>77 fn max_vals(&self) -> Option<u64> { 78 (*self).max_vals() 79 } min_vals(&self) -> Option<u64>80 fn min_vals(&self) -> Option<u64> { 81 (*self).min_vals() 82 } num_vals(&self) -> Option<u64>83 fn num_vals(&self) -> Option<u64> { 84 (*self).num_vals() 85 } possible_vals(&self) -> Option<&[&'e str]>86 fn possible_vals(&self) -> Option<&[&'e str]> { 87 (*self).possible_vals() 88 } validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>89 fn validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>> { 90 (*self).validator() 91 } validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>>92 fn validator_os(&self) -> Option<&Rc<Fn(&OsStr) -> Result<(), OsString>>> { 93 (*self).validator_os() 94 } short(&self) -> Option<char>95 fn short(&self) -> Option<char> { 96 (*self).short() 97 } long(&self) -> Option<&'e str>98 fn long(&self) -> Option<&'e str> { 99 (*self).long() 100 } val_delim(&self) -> Option<char>101 fn val_delim(&self) -> Option<char> { 102 (*self).val_delim() 103 } takes_value(&self) -> bool104 fn takes_value(&self) -> bool { 105 (*self).takes_value() 106 } val_names(&self) -> Option<&VecMap<&'e str>>107 fn val_names(&self) -> Option<&VecMap<&'e str>> { 108 (*self).val_names() 109 } help(&self) -> Option<&'e str>110 fn help(&self) -> Option<&'e str> { 111 (*self).help() 112 } long_help(&self) -> Option<&'e str>113 fn long_help(&self) -> Option<&'e str> { 114 (*self).long_help() 115 } default_val(&self) -> Option<&'e OsStr>116 fn default_val(&self) -> Option<&'e OsStr> { 117 (*self).default_val() 118 } default_vals_ifs(&self) -> Option<map::Values<(&'n str, Option<&'e OsStr>, &'e OsStr)>>119 fn default_vals_ifs(&self) -> Option<map::Values<(&'n str, Option<&'e OsStr>, &'e OsStr)>> { 120 (*self).default_vals_ifs() 121 } env<'s>(&'s self) -> Option<(&'n OsStr, Option<&'s OsString>)>122 fn env<'s>(&'s self) -> Option<(&'n OsStr, Option<&'s OsString>)> { 123 (*self).env() 124 } longest_filter(&self) -> bool125 fn longest_filter(&self) -> bool { 126 (*self).longest_filter() 127 } val_terminator(&self) -> Option<&'e str>128 fn val_terminator(&self) -> Option<&'e str> { 129 (*self).val_terminator() 130 } 131 } 132