<commit_before>use crate::{
    compiler::{hir_to_lir::HirToLir, lir::Lir},
    database::Database,
    input::{Input, InputDb},
};

pub trait UseProvider {
    fn use_asset(&self, input: Input) -> Result<Vec<u8>, String>;
    fn use_local_module(&self, input: Input) -> Option<Lir>;
}

pub struct DbUseProvider<'a> {
    pub db: &'a Database,
}
impl<'a> UseProvider for DbUseProvider<'a> {
    fn use_asset(&self, input: Input) -> Result<Vec<u8>, String> {
        self.db
            .get_input(input.clone())
            .map(|bytes| (*bytes).clone())
            .ok_or_else(|| format!("Couldn't import file '{}'.", input))
    }

    fn use_local_module(&self, input: Input) -> Option<Lir> {
        self.db.lir(input).map(|lir| (*lir).clone())
    }
}

pub struct FunctionUseProvider<'a, U1, U2>
where
    U1: Fn(Input) -> Result<Vec<u8>, String>,
    U2: Fn(Input) -> Option<Lir>,
{
    pub use_asset: &'a U1,
    pub use_local_module: &'a U2,
}
impl<'a, U1, U2> UseProvider for FunctionUseProvider<'a, U1, U2>
where
    U1: Fn(Input) -> Result<Vec<u8>, String>,
    U2: Fn(Input) -> Option<Lir>,
{
    fn use_asset(&self, input: Input) -> Result<Vec<u8>, String> {
        (self.use_asset)(input)
    }

    fn use_local_module(&self, input: Input) -> Option<Lir> {
        (self.use_local_module)(input)
    }
}<commit_msg>Remove FunctionUseProvider<commit_after>use crate::{
    compiler::{hir_to_lir::HirToLir, lir::Lir},
    database::Database,
    input::{Input, InputDb},
};

pub trait UseProvider {
    fn use_asset(&self, input: Input) -> Result<Vec<u8>, String>;
    fn use_local_module(&self, input: Input) -> Option<Lir>;
}

pub struct DbUseProvider<'a> {
    pub db: &'a Database,
}
impl<'a> UseProvider for DbUseProvider<'a> {
    fn use_asset(&self, input: Input) -> Result<Vec<u8>, String> {
        self.db
            .get_input(input.clone())
            .map(|bytes| (*bytes).clone())
            .ok_or_else(|| format!("Couldn't import file '{}'.", input))
    }

    fn use_local_module(&self, input: Input) -> Option<Lir> {
        self.db.lir(input).map(|lir| (*lir).clone())
    }
}
{'fraction_non_alphanumeric': 0.18353831598864712, 'fraction_numerical': 0.008987701040681173, 'mean_word_length': 3.316326530612245, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3493905', 'n_tokens_mistral': 781, 'n_tokens_neox': 787, 'n_words': 159}