Added dictionary plugin and switched from a Mutex to an RwLock in the anyrun_plugin crate

This change means that `get_matches` no longer has access to a mutable version of the
state of the plugin. A redesign is needed to allow for this if needed.
This commit is contained in:
Kirottu
2023-04-29 18:18:47 +03:00
parent 3a1648cf37
commit beaf2549ac
13 changed files with 162 additions and 31 deletions
+6 -6
View File
@@ -18,13 +18,13 @@ impl Default for Config {
}
}
struct RuntimeData {
struct State {
config: Config,
langs: Vec<(&'static str, &'static str)>,
}
fn init(config_dir: RString) -> RuntimeData {
RuntimeData {
fn init(config_dir: RString) -> State {
State {
config: match fs::read_to_string(format!("{}/translate.ron", config_dir)) {
Ok(content) => ron::from_str(&content).unwrap_or_default(),
Err(_) => Config::default(),
@@ -145,7 +145,7 @@ fn info() -> PluginInfo {
}
}
fn get_matches(input: RString, data: &mut RuntimeData) -> RVec<Match> {
fn get_matches(input: RString, data: &State) -> RVec<Match> {
if !input.starts_with(&data.config.prefix) {
return RVec::new();
}
@@ -227,8 +227,8 @@ fn get_matches(input: RString, data: &mut RuntimeData) -> RVec<Match> {
})
}
fn handler(selection: Match, _data: &mut RuntimeData) -> HandleResult {
fn handler(selection: Match, _data: &mut State) -> HandleResult {
HandleResult::Copy(selection.title.into_bytes())
}
plugin!(init, info, get_matches, handler, RuntimeData);
plugin!(init, info, get_matches, handler, State);