mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
common.rs: port get_by_sorted_name()
This commit is contained in:
parent
c6b8b7548f
commit
9d436ee5e9
1 changed files with 13 additions and 0 deletions
|
@ -1971,6 +1971,19 @@ macro_rules! assert_sorted_by_name {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Named {
|
||||||
|
fn name(&self) -> &'static wstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \return a pointer to the first entry with the given name, assuming the entries are sorted by
|
||||||
|
/// name. \return nullptr if not found.
|
||||||
|
pub fn get_by_sorted_name<T: Named>(name: &wstr, vals: &'static [T]) -> Option<&'static T> {
|
||||||
|
match vals.binary_search_by_key(&name, |val| val.name()) {
|
||||||
|
Ok(index) => Some(&vals[index]),
|
||||||
|
Err(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! fwprintf {
|
macro_rules! fwprintf {
|
||||||
($fd:expr, $format:literal $(, $arg:expr)*) => {
|
($fd:expr, $format:literal $(, $arg:expr)*) => {
|
||||||
|
|
Loading…
Reference in a new issue