1
0
Fork 0
forked from koniifer/ableos
ableos-framebuffer/ableos/src/alias_table/mod.rs
2022-01-27 01:37:12 -06:00

29 lines
756 B
Rust

use alloc::string::{String, ToString};
use hashbrown::HashMap;
lazy_static::lazy_static! {
pub static ref ALIAS_TABLE: spin::Mutex<AliasTable> = spin::Mutex::new(AliasTable::new());
}
/// A table of aliases
///
/// This is used to allow users to specify aliases for files and commands
pub struct AliasTable {
pub table: HashMap<String, String>,
}
impl AliasTable {
pub fn new() -> Self {
Self {
table: HashMap::new(),
}
}
pub fn add_alias(&mut self, alias: String, path: String) {
self.table.insert(alias, path);
}
pub fn get_alias(&self, alias: String) -> Option<String> {
let alias_table = ALIAS_TABLE.lock();
alias_table.table.get(&alias).map(|x| x.to_string())
}
}