Made `lookup_plugin_name()` return an `IntoIterator` for if we allow dirs to be plugins in the future. (Currently, it will always be just `Option`)

Added `PluginTrust<"a>: Cow<"a, Path>` as return type from this iterator, so the caller can know the trust of the path the plugin was loaded from.

Fortune for rng's current commit: Future blessing − 末吉
plugin
Avril 2 years ago
parent 0a7e4286b3
commit f462d11025
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -6,6 +6,9 @@ use std::path::{
};
use std::{
fs, io,
borrow::{
Cow, Borrow,
},
//collections::HashMap,
};
use regex::{
@ -558,7 +561,89 @@ impl<P: AsRef<Path>> LookupVisitor<P>
}
}
pub fn lookup_plugin_name(name: impl AsRef<str>) -> Option<PathBuf>
/// 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(<path>) for each path in `locations`, then call `start_lookup(<trusted path>, name)` on each *in order* specified in `locations`")
Trusted(Cow<'a, Path>),
Untrusted(Cow<'a, Path>)
}
impl<'a> Borrow<Path> for PluginTrust<'a>
{
#[inline(always)]
fn borrow(&self) -> &Path
{
match self {
Self::Trusted(a) | Self::Untrusted(a) => a.borrow()
}
}
}
impl<'a> AsRef<Path> for PluginTrust<'a>
{
#[inline]
fn as_ref(&self) -> &Path
{
self.borrow()
}
}
impl<'a> From<PluginTrust<'a>> for Cow<'a, Path>
{
#[inline]
fn from(from: PluginTrust<'a>) -> Self
{
match from {
PluginTrust::Trusted(a) | PluginTrust::Untrusted(a) => a
}
}
}
impl<'a, T: AsRef<Path> + ?Sized> PartialEq<T> 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<PluginTrust<'static>> 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<str>) -> impl IntoIterator<Item = PluginTrust<'static>> + Send + 'static
{
todo!("Create a LookupVisitor(<path>) for each path in `locations`, then call `start_lookup(<trusted path>, name)` on each *in order* specified in `locations`");
None::<PluginTrust> //TODO: ^ see above
}

Loading…
Cancel
Save