diff --git a/espanso-render/src/extension/clipboard.rs b/espanso-render/src/extension/clipboard.rs index e42743e..07030c9 100644 --- a/espanso-render/src/extension/clipboard.rs +++ b/espanso-render/src/extension/clipboard.rs @@ -24,18 +24,18 @@ pub trait ClipboardProvider { fn get_text(&self) -> Option; } -pub struct ClipboardExtension { - provider: Box, +pub struct ClipboardExtension<'a> { + provider: &'a dyn ClipboardProvider, } #[allow(clippy::new_without_default)] -impl ClipboardExtension { - pub fn new(provider: Box) -> Self { +impl <'a> ClipboardExtension<'a> { + pub fn new(provider: &'a dyn ClipboardProvider) -> Self { Self { provider } } } -impl Extension for ClipboardExtension { +impl <'a> Extension for ClipboardExtension<'a> { fn name(&self) -> &str { "clipboard" } @@ -76,7 +76,7 @@ mod tests { #[test] fn clipboard_works_correctly() { let provider = MockClipboardProvider { return_none: false }; - let extension = ClipboardExtension::new(Box::new(provider)); + let extension = ClipboardExtension::new(&provider); assert_eq!( extension @@ -90,7 +90,7 @@ mod tests { #[test] fn none_clipboard_produces_error() { let provider = MockClipboardProvider { return_none: true }; - let extension = ClipboardExtension::new(Box::new(provider)); + let extension = ClipboardExtension::new(&provider); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), &Params::new()), diff --git a/espanso-render/src/extension/script.rs b/espanso-render/src/extension/script.rs index 14491dd..557406b 100644 --- a/espanso-render/src/extension/script.rs +++ b/espanso-render/src/extension/script.rs @@ -179,6 +179,7 @@ pub enum ScriptExtensionError { #[cfg(test)] mod tests { use super::*; + #[cfg(not(target_os = "windows"))] use crate::Scope; use std::iter::FromIterator; diff --git a/espanso-render/src/lib.rs b/espanso-render/src/lib.rs index de82293..a07741d 100644 --- a/espanso-render/src/lib.rs +++ b/espanso-render/src/lib.rs @@ -31,7 +31,7 @@ pub trait Renderer { -> RenderResult; } -pub fn create(extensions: Vec>) -> impl Renderer { +pub fn create<'a>(extensions: Vec<&'a dyn Extension>) -> impl Renderer + 'a { renderer::DefaultRenderer::new(extensions) } diff --git a/espanso-render/src/renderer/mod.rs b/espanso-render/src/renderer/mod.rs index ce0afff..958ac0e 100644 --- a/espanso-render/src/renderer/mod.rs +++ b/espanso-render/src/renderer/mod.rs @@ -36,12 +36,12 @@ lazy_static! { static ref WORD_REGEX: Regex = Regex::new(r"(\w+)").unwrap(); } -pub(crate) struct DefaultRenderer { - extensions: HashMap>, +pub(crate) struct DefaultRenderer<'a> { + extensions: HashMap, } -impl DefaultRenderer { - pub fn new(extensions: Vec>) -> Self { +impl <'a> DefaultRenderer<'a> { + pub fn new(extensions: Vec<&'a dyn Extension>) -> Self { let extensions = extensions .into_iter() .map(|ext| (ext.name().to_string(), ext)) @@ -50,7 +50,7 @@ impl DefaultRenderer { } } -impl Renderer for DefaultRenderer { +impl <'a> Renderer for DefaultRenderer<'a> { fn render( &self, template: &Template, @@ -287,7 +287,7 @@ mod tests { } pub fn get_renderer() -> impl Renderer { - DefaultRenderer::new(vec![Box::new(MockExtension {})]) + DefaultRenderer::new(vec![&MockExtension {}]) } pub fn template_for_str(str: &str) -> Template {