use crate::formatter::Formatter;
use crate::loader::Loader;
pub struct RegisteredLoader(pub &'static dyn Loader);
pub struct RegisteredFormatter(pub &'static dyn Formatter);
inventory::collect!(RegisteredLoader);
inventory::collect!(RegisteredFormatter);
pub fn collect_formatters() -> Vec<&'static dyn Formatter> {
inventory::iter::<RegisteredFormatter>
.into_iter()
.map(|r| r.0)
.collect()
}
pub fn find_loader(identifier: &str) -> Option<&'static dyn Loader> {
for entry in inventory::iter::<RegisteredLoader> {
if entry.0.provides(identifier) {
return Some(entry.0);
}
}
None
}
pub fn find_formatter(source: &str) -> Option<&'static dyn Formatter> {
for entry in inventory::iter::<RegisteredFormatter> {
if entry.0.provides(source) {
return Some(entry.0);
}
}
None
}
pub fn find_formatter_by_hint(hint: &str) -> Option<&'static dyn Formatter> {
for entry in inventory::iter::<RegisteredFormatter> {
if entry.0.extensions().contains(&hint) {
return Some(entry.0);
}
}
None
}