use std::path::PathBuf;
use std::sync::Arc;
use pedant_types::{SourcePath, SourceProvider, SourceRecord};
use super::record_cache::RecordCache;
use super::source_language::SourceLanguage;
#[derive(Debug)]
pub struct SourceProviderOf<Rules, Inventory> {
cache: RecordCache<Inventory>,
rules: Rules,
}
impl<Rules, Inventory> SourceProviderOf<Rules, Inventory> {
pub(crate) fn at_canonical_root(root: PathBuf, rules: Rules) -> Self {
Self {
cache: RecordCache::new(root),
rules,
}
}
pub fn retained(&self, path: &str) -> Option<&SourceRecord<Inventory>> {
self.cache.retained(path)
}
pub fn admitted_paths(&self) -> Box<[Arc<str>]> {
self.cache.admitted_paths()
}
pub fn admitted_sources(&self) -> usize {
self.cache.admitted_sources()
}
pub fn retained_bytes(&self) -> u64 {
self.cache.retained_bytes()
}
}
impl<Rules, Inventory, Fault> SourceProvider<Inventory> for SourceProviderOf<Rules, Inventory>
where
Rules: SourceLanguage<Inventory = Inventory, Fault = Fault>,
{
type Error = Fault;
fn source(&mut self, path: SourcePath<'_>) -> Result<SourceRecord<Inventory>, Self::Error> {
self.cache.source(&self.rules, path)
}
}