Skip to content

Commit

Permalink
feat(plugin): remove use of String and use Cow<str>
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Mar 13, 2024
1 parent 6f70f73 commit c44d7bd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions fluere-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::sync::Arc;
mod downloader;
mod util;

use std::borrow::Cow;

use downloader::download_plugin_from_github;
use util::home_cache_path;

Expand All @@ -19,7 +21,7 @@ pub struct PluginManager {
lua: Arc<Mutex<Lua>>,
sender: mpsc::Sender<FluereRecord>,
receiver: Arc<Mutex<mpsc::Receiver<FluereRecord>>>,
plugins: Arc<Mutex<HashSet<String>>>,
plugins: Arc<Mutex<HashSet<Cow<'static, str>>>>,
}

impl PluginManager {
Expand Down Expand Up @@ -98,8 +100,7 @@ impl PluginManager {
Ok(())
}).expect(format!("Error on plugin: {}", name).as_str(()));*/
//lua_guard.load(&code).exec().expect(format!("Error on plugin: {}", name).as_str());

plugins_guard.insert(name.clone());
let _ = plugins_guard.insert(std::borrow::Cow::Owned(name.clone()));
#[cfg(feature = "log")]
info!("Loaded plugin {}", name);
#[cfg(not(feature = "log"))]
Expand Down Expand Up @@ -168,7 +169,7 @@ impl PluginManager {
Ok(())
}).expect(format!("Error on plugin: {}", name).as_str());*/
plugins_guard.insert(name.clone());
let _ = plugins_guard.insert(std::borrow::Cow::Owned(name.clone()));
#[cfg(feature = "log")]
info!("Loaded plugin {}", name);
#[cfg(not(feature = "log"))]
Expand Down Expand Up @@ -267,7 +268,7 @@ impl PluginManager {
for plugin_name in plugins.iter() {
let plugin_table: mlua::Table = lua
.globals()
.get(plugin_name.as_str())
.get(plugin_name.as_ref())
.expect("Plugin table not found");

if let Ok(func) = plugin_table.get::<_, mlua::Function>("process_data") {
Expand Down Expand Up @@ -313,7 +314,7 @@ impl PluginManager {
for plugin_name in plugins.iter() {
let plugin_table: mlua::Table = lua
.globals()
.get(plugin_name.as_str())
.get(plugin_name.as_ref())
.expect("Plugin table not found");

if let Ok(func) = plugin_table.get::<_, mlua::Function>("cleanup") {
Expand All @@ -332,3 +333,10 @@ impl PluginManager {
drop(worker);
}
}

impl Drop for PluginManager {
fn drop(&mut self) {
drop(self.plugins.lock());
drop(self.lua.lock());
}
}

0 comments on commit c44d7bd

Please sign in to comment.