| 1 | use superrust-analyzer cargo jargon-args 0.2.5 crate/::Errorrust-analyzer cargo jargon-args 0.2.5 error/Error#; |
| 2 | use superrust-analyzer cargo jargon-args 0.2.5 crate/::Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 5 | |
| 6 | /// # Jargon |
| 7 | /// |
| 8 | /// This is the main struct in this crate. This is what is used to handle arguments, |
| 9 | /// and get arguments' values. |
| 10 | /// |
| 11 | /// # Example |
| 12 | /// |
| 13 | /// ``` |
| 14 | /// use jargon_args::Jargon; |
| 15 | /// let mut jargon: Jargon = Jargon::from_env(); |
| 16 | /// |
| 17 | /// if jargon.contains(["-h", "--help"]) { |
| 18 | /// println!("help text"); |
| 19 | /// std::process::exit(0); |
| 20 | /// } |
| 21 | /// |
| 22 | /// // ... |
| 23 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 24 | pub struct Jargonrust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#(pub(craterust-analyzer cargo jargon-args 0.2.5 crate/) Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>); |
| 25 | |
| 26 | impl Jargonrust-analyzer cargo jargon-args 0.2.5 jargons/Jargon# { |
| 27 | /// Extracts a program's arguments from the environment. |
| 28 | pub fn from_envrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]from_env().() -> Selfrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon] { |
| 29 | Selfrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon](stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 30 | } |
| 31 | |
| 32 | /// Places provided vector into Jargon. Please have the program's name or subcommand's name at |
| 33 | /// index `0`. 0 is always ignored. |
| 34 | pub fn from_vecrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]from_vec().<T: ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#>(v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>) -> Selfrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon] { |
| 35 | Selfrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon](v.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 36 | } |
| 37 | |
| 38 | /// Checks if provided key is given in arguments. Removes it. |
| 39 | pub fn containsrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]contains().<K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>>(&mut self, key: K) -> bool { |
| 40 | let key: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 41 | let len: usize = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 42 | |
| 43 | match key { |
| 44 | Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#::Dualrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual# { |
| 45 | charrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual#char.: c, |
| 46 | s_txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual#s_txt.: s, |
| 47 | l_txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual#l_txt.: l, |
| 48 | } => { |
| 49 | let s: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#::Shortrust-analyzer cargo jargon-args 0.2.5 keys/Key#Short# { charrust-analyzer cargo jargon-args 0.2.5 keys/Key#Short#char.: c, txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Short#txt.: s }; |
| 50 | let l: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#::Longrust-analyzer cargo jargon-args 0.2.5 keys/Key#Long# { charrust-analyzer cargo jargon-args 0.2.5 keys/Key#Long#char.: c, txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Long#txt.: l }; |
| 51 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#len { |
| 52 | let cont: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 53 | if cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().s || cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().l { |
| 54 | self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(i); |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | key => { |
| 60 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#len { |
| 61 | let cont: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 62 | if cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().key { |
| 63 | self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(i); |
| 64 | return true; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | false |
| 71 | } |
| 72 | |
| 73 | #[cfg(feature = "no_mut")] |
| 74 | /// Checks if provided key is given in arguments. Dose not remove it. |
| 75 | pub fn contains_nomutrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]contains_nomut().<K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>>(&self, key: K) -> bool { |
| 76 | let m = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(); |
| 77 | let mut m = Selfrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon](m); |
| 78 | m.containsrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]contains().(key) |
| 79 | } |
| 80 | |
| 81 | /// Runs function that does not return a value if specified key exists. |
| 82 | /// Removes the program's name from provided vector. |
| 83 | pub fn on_subcommandrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]on_subcommand().<K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>)>(&mut self, key: K, mut f: F) { |
| 84 | let key: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 85 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 86 | let cont: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 87 | if cont.is_subrust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key]is_sub().() && cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().key { |
| 88 | return f(self.clonerust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon][Clone]clone().().finishrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]finish().()); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /// Runs function that returns Option<T> if specified key exists. |
| 94 | /// Removes the program's name from provided vector. |
| 95 | pub fn opt_on_subcommandrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]opt_on_subcommand().<K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>, T>( |
| 96 | &mut self, |
| 97 | key: K, |
| 98 | mut f: F, |
| 99 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 100 | let key: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 101 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 102 | let cont: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 103 | if cont.is_subrust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key]is_sub().() && cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().key { |
| 104 | return f(self.clonerust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon][Clone]clone().().finishrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]finish().()); |
| 105 | } |
| 106 | } |
| 107 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 108 | } |
| 109 | |
| 110 | /// Runs function that returns Result<T, jargon_args::Error> if specified key exists. |
| 111 | /// Removes the program's name from provided vector. |
| 112 | pub fn res_on_subcommandrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]res_on_subcommand().<K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo jargon-args 0.2.5 error/Error#>, T>( |
| 113 | &mut self, |
| 114 | key: K, |
| 115 | mut f: F, |
| 116 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo jargon-args 0.2.5 error/Error#> { |
| 117 | let key: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 118 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 119 | let cont: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 120 | if cont.is_subrust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key]is_sub().() && cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().key { |
| 121 | return f(self.clonerust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon][Clone]clone().().finishrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]finish().()); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo jargon-args 0.2.5 error/Error#::MissingArgrust-analyzer cargo jargon-args 0.2.5 error/Error#MissingArg#(key)) |
| 126 | } |
| 127 | |
| 128 | /// Checks if key exists, removes it, and returns it and all remaining arguments in |
| 129 | /// Some(Vec<String>). None if key isn't in arguments. |
| 130 | pub fn subcommandrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]subcommand().<K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>>(&mut self, key: K) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> { |
| 131 | let mut v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 132 | self.on_subcommandrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]on_subcommand().(key, |vv| v = vv); |
| 133 | if v.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 134 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 135 | } else { |
| 136 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | #[cfg(feature = "no_mut")] |
| 141 | /// Checks if key exists, removes it without modifying your Jargon variable, |
| 142 | /// and returns it and all remaining arguments in |
| 143 | /// Some(Vec<String>). None if key isn't in arguments. |
| 144 | pub fn subcommand_nomutrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]subcommand_nomut().<K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>>(&self, key: K) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> { |
| 145 | Jargonrust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#::from_vecrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]from_vec().(self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()).subcommandrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]subcommand().(key) |
| 146 | } |
| 147 | |
| 148 | /// Checks for provided key in arguments, removes it, returns Some(String) with the value after it if there is one. |
| 149 | /// None is there is no value. |
| 150 | pub fn option_argrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]option_arg().<T: FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#, K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>>(&mut self, key: K) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 151 | let key: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 152 | let len: usize = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 153 | |
| 154 | match key { |
| 155 | Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#::Dualrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual# { |
| 156 | charrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual#char.: c, |
| 157 | s_txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual#s_txt.: s, |
| 158 | l_txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Dual#l_txt.: l, |
| 159 | } => { |
| 160 | let s: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#::Shortrust-analyzer cargo jargon-args 0.2.5 keys/Key#Short# { charrust-analyzer cargo jargon-args 0.2.5 keys/Key#Short#char.: c, txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Short#txt.: s }; |
| 161 | let l: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#::Longrust-analyzer cargo jargon-args 0.2.5 keys/Key#Long# { charrust-analyzer cargo jargon-args 0.2.5 keys/Key#Long#char.: c, txtrust-analyzer cargo jargon-args 0.2.5 keys/Key#Long#txt.: l }; |
| 162 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#len { |
| 163 | let cont: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 164 | if cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().s || cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().l { |
| 165 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 { |
| 166 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 167 | } |
| 168 | return if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(s.charrust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key]char().()) |
| 169 | || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(l.charrust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key]char().()) |
| 170 | { |
| 171 | self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(i); |
| 172 | self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(i).parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 173 | } else { |
| 174 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 175 | }; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | key => { |
| 180 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#len { |
| 181 | let cont: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 182 | if cont rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().==rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq(). rust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][`PartialEq<Self>`]eq().key { |
| 183 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 { |
| 184 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 185 | } |
| 186 | return if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(key.charrust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key]char().()) { |
| 187 | self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(i); |
| 188 | self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(i).parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 189 | } else { |
| 190 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 191 | }; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 198 | } |
| 199 | |
| 200 | /// Checks for provided key in arguments, removes it, returns Ok(String) with the value after it if there is one. |
| 201 | /// Err(jargon_args::Error) is there is no value. |
| 202 | pub fn result_argrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]result_arg().<T: FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#, K: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key#>>(&mut self, key: K) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo jargon-args 0.2.5 error/Error#> { |
| 203 | let key: Keyrust-analyzer cargo jargon-args 0.2.5 keys/Key# = key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 204 | self.option_argrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]option_arg().(key.clonerust-analyzer cargo jargon-args 0.2.5 keys/impl#[Key][Clone]clone().()).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo jargon-args 0.2.5 error/Error#::MissingArgrust-analyzer cargo jargon-args 0.2.5 error/Error#MissingArg#(key)) |
| 205 | } |
| 206 | |
| 207 | /// Drops your jargon instance and returns all remaining arguments. |
| 208 | pub fn finishrust-analyzer cargo jargon-args 0.2.5 jargons/impl#[Jargon]finish().(self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 209 | self.0rust-analyzer cargo jargon-args 0.2.5 jargons/Jargon#0..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 210 | } |
| 211 | } |