impl MKeyMap { /// If any arg has corresponding key in this map, we can search the key with /// `u64` (for positional argument), `char` (for short flag), `&str` and `OsString` /// (for long flag) pub(crate) fn contains<K>(&self, key: K) -> bool where
KeyType: PartialEq<K>,
{ self.keys.iter().any(|x| x.key == key)
}
/// Push an argument in the map. pub(crate) fn push(&mutself, new_arg: Arg) { self.args.push(new_arg);
}
/// Find the arg have corresponding key in this map, we can search the key /// with `u64` (for positional argument), `char` (for short flag), `&str` and /// `OsString` (for long flag) pub(crate) fn get<K: ?Sized>(&self, key: &K) -> Option<&Arg> where
KeyType: PartialEq<K>,
{ self.keys
.iter()
.find(|k| &k.key == key)
.map(|k| &self.args[k.index])
}
/// Return iterators of all keys. pub(crate) fn keys(&self) -> impl Iterator<Item = &KeyType> { self.keys.iter().map(|x| &x.key)
}
/// Return iterators of all args. pub(crate) fn args(&self) -> impl Iterator<Item = &Arg> { self.args.iter()
}
/// Return mutable iterators of all args. pub(crate) fn args_mut(&mutself) -> impl Iterator<Item = &='color:red'>mut Arg> { self.args.iter_mut()
}
/// We need a lazy build here since some we may change args after creating /// the map, you can checkout who uses `args_mut`. pub(crate) fn _build(&mutself) { // There will be at least as many keys as args, so that is a good starting point self.keys.reserve(self.args.len()); for (i, arg) inself.args.iter().enumerate() {
append_keys(&mutself.keys, arg, i);
}
}
/// Remove an arg in the graph by Id, usually used by `mut_arg`. Return /// `Some(arg)` if removed. pub(crate) fn remove_by_name(&mutself, name: &str) -> Option<Arg> { self.args
.iter()
.position(|arg| arg.id == name) // since it's a cold function, using this wouldn't hurt much
.map(|i| self.args.remove(i))
}
}
impl Index<&'_ KeyType> for MKeyMap { type Output = Arg;
/// Generate key types for an specific Arg. fn append_keys(keys: &mut Vec<Key>, arg: &Arg, index: usize) { iflet Some(pos_index) = arg.index { let key = KeyType::Position(pos_index);
keys.push(Key { key, index });
} else { iflet Some(short) = arg.short { let key = KeyType::Short(short);
keys.push(Key { key, index });
} iflet Some(long) = arg.long.clone() { let key = KeyType::Long(long.into());
keys.push(Key { key, index });
}
for (short, _) in arg.short_aliases.iter() { let key = KeyType::Short(*short);
keys.push(Key { key, index });
} for (long, _) in arg.aliases.iter() { let key = KeyType::Long(long.into());
keys.push(Key { key, index });
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.