use std::sync::Arc;
use super::loader::LoadedPlugin;
use super::manifest::PluginManifest;
#[derive(Debug, Default, Clone)]
pub struct PluginRegistry {
files: Arc<Vec<LoadedPlugin>>,
}
impl PluginRegistry {
#[must_use]
pub fn new(files: Vec<LoadedPlugin>) -> Self {
Self { files: Arc::new(files) }
}
#[must_use]
pub fn files(&self) -> &[LoadedPlugin] {
&self.files
}
pub fn tools(&self) -> impl Iterator<Item = &PluginManifest> {
self.files.iter().flat_map(|f| f.tools.iter())
}
#[must_use]
pub fn get_tool(&self, name: &str) -> Option<&PluginManifest> {
self.tools().find(|t| t.name == name)
}
pub fn promoted_tools(&self) -> impl Iterator<Item = &PluginManifest> {
self.tools().filter(|t| t.is_tool())
}
#[must_use]
pub fn tool_count(&self) -> usize {
self.files.iter().map(|f| f.tools.len()).sum()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.files.is_empty()
}
}