use deno_core::{
ModuleCodeBytes, ModuleSource, ModuleSourceCode, ModuleSpecifier, SourceCodeCacheInfo,
};
pub trait ClonableSource {
fn clone(&self, specifier: &ModuleSpecifier) -> ModuleSource;
}
impl ClonableSource for ModuleSource {
fn clone(&self, specifier: &ModuleSpecifier) -> ModuleSource {
ModuleSource::new(
self.module_type.clone(),
match &self.code {
ModuleSourceCode::String(s) => ModuleSourceCode::String(s.to_string().into()),
ModuleSourceCode::Bytes(b) => {
ModuleSourceCode::Bytes(ModuleCodeBytes::Boxed(b.to_vec().into()))
}
},
specifier,
self.code_cache.as_ref().map(|c| SourceCodeCacheInfo {
hash: c.hash,
data: c.data.clone(),
}),
)
}
}
#[deprecated(
since = "0.7.0",
note = "This trait is being replaced by the `ImportProvider` trait, which provides more control over module resolution. See the `module_loader_cache` example for more information."
)]
pub trait ModuleCacheProvider {
fn set(&mut self, specifier: &ModuleSpecifier, source: ModuleSource);
fn get(&self, specifier: &ModuleSpecifier) -> Option<ModuleSource>;
}