diff --git a/src/plugin/searcher.rs b/src/plugin/searcher.rs index b8f1621..f18bb93 100644 --- a/src/plugin/searcher.rs +++ b/src/plugin/searcher.rs @@ -6,6 +6,9 @@ use std::path::{ }; use std::{ fs, io, + borrow::{ + Cow, Borrow, + }, //collections::HashMap, }; use regex::{ @@ -558,7 +561,89 @@ impl> LookupVisitor

} } -pub fn lookup_plugin_name(name: impl AsRef) -> Option +/// Denoted a plugin and if it was loaded from a trusted path or not +#[derive(Debug, Clone, Eq, Hash, PartialOrd, Ord)] +pub enum PluginTrust<'a> { - todo!("Create a LookupVisitor() for each path in `locations`, then call `start_lookup(, name)` on each *in order* specified in `locations`") + Trusted(Cow<'a, Path>), + Untrusted(Cow<'a, Path>) +} + +impl<'a> Borrow for PluginTrust<'a> +{ + #[inline(always)] + fn borrow(&self) -> &Path + { + match self { + Self::Trusted(a) | Self::Untrusted(a) => a.borrow() + } + } +} + +impl<'a> AsRef for PluginTrust<'a> +{ + #[inline] + fn as_ref(&self) -> &Path + { + self.borrow() + } +} + +impl<'a> From> for Cow<'a, Path> +{ + #[inline] + fn from(from: PluginTrust<'a>) -> Self + { + match from { + PluginTrust::Trusted(a) | PluginTrust::Untrusted(a) => a + } + } +} + +impl<'a, T: AsRef + ?Sized> PartialEq for PluginTrust<'a> +{ + #[inline] + fn eq(&self, other: &T) -> bool + { + other.as_ref() == self.as_ref() + } +} + +impl<'a> PluginTrust<'a> +{ + /// Was this plugin loaded from a trusted path? + #[inline(always)] + pub fn is_trusted(&self) -> bool + { + if let Self::Trusted(_) = self { + true + } else { + false + } + } + + /// Was this plugin loaded from an untrusted path? + #[inline] + pub fn is_untrusted(&self) -> bool + { + !self.is_trusted() + } +} + +impl From> for PathBuf +{ + #[inline] + fn from(from: PluginTrust<'static>) -> Self + { + match from { + PluginTrust::Trusted(a) | PluginTrust::Untrusted(a) => a.into_owned() + } + } +} + + +pub fn lookup_plugin_name(name: impl AsRef) -> impl IntoIterator> + Send + 'static +{ + todo!("Create a LookupVisitor() for each path in `locations`, then call `start_lookup(, name)` on each *in order* specified in `locations`"); + None:: //TODO: ^ see above }