conf/shortcuts.rs: add key_slice() method to shortcut structs
Add a new method that returns a static slice of included shortcuts.feature/perform-shortcut
parent
0ef4dde939
commit
96f9aa8072
|
@ -86,8 +86,7 @@ macro_rules! shortcut_key_values {
|
|||
pub struct $name:ident { $($fname:ident |> $fdesc:literal |> $default:expr),* }) => {
|
||||
$(#[$outer])*
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
#[serde(rename = $cname)]
|
||||
#[serde(default, deny_unknown_fields, rename = $cname)]
|
||||
pub struct $name {
|
||||
$(pub $fname : Key),*
|
||||
}
|
||||
|
@ -100,12 +99,28 @@ macro_rules! shortcut_key_values {
|
|||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a hashmap of all shortcuts and their values
|
||||
pub fn key_values(&self) -> IndexMap<&'static str, Key> {
|
||||
[
|
||||
$((stringify!($fname),(self.$fname).clone()),)*
|
||||
].iter().cloned().collect()
|
||||
}
|
||||
|
||||
/// Returns a slice of all shortcuts.
|
||||
pub fn key_slice(&self) -> &'static [&'static str] {
|
||||
use std::sync::Once;
|
||||
|
||||
static mut VAL: Vec<&'static str> = vec![];
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
unsafe {
|
||||
INIT.call_once(|| {
|
||||
$(VAL.push(stringify!($fname));)*
|
||||
});
|
||||
VAL.as_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for $name {
|
||||
|
|
Loading…
Reference in New Issue