From ec747e2e27304a62ded96357ed2b7c18ad95615a Mon Sep 17 00:00:00 2001 From: yuma14 Date: Tue, 19 Dec 2023 02:22:08 +0900 Subject: [PATCH] refactor: remove byte_map in `Resource` --- src/pipeline.rs | 20 +------------------- src/pipeline/resource.rs | 10 +--------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/pipeline.rs b/src/pipeline.rs index b2a38c5..2703b58 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -81,27 +81,9 @@ impl Pipeline { let _enter = step_span.enter(); debug!("start"); match step { - Step::Load { key, with, .. } => { + Step::Load { key, .. } => { if let Some(value) = resource.get_value(&index) { store.set(key.to_string(), value.clone()); - } else if let Some(bytes) = resource.get_bytes(&index) { - let value = match with { - EnumLoader::Template => TemplateLoader::load(bytes), - EnumLoader::Json => JsonLoader::load(bytes), - EnumLoader::TextWithFrontmatter => { - TextWithFrontmatterLoader::load(bytes) - } - EnumLoader::Blob => BlobLoader::load(bytes), - EnumLoader::Text => TextLoader::load(bytes), - EnumLoader::Yaml => YamlLoader::load(bytes), - } - .with_context(|| { - format!( - "failed to load {} with {:?} Loader (steps index: {})", - key, self.entry.type_, index - ) - })?; - store.set(key.to_string(), value); } else { anyhow::bail!("no value prefetched for key {}", key); } diff --git a/src/pipeline/resource.rs b/src/pipeline/resource.rs index 41a2a16..54c501e 100644 --- a/src/pipeline/resource.rs +++ b/src/pipeline/resource.rs @@ -15,7 +15,6 @@ use super::Pipeline; /// One resource instance is created per [`Pipeline`](crate::pipeline::Pipeline). #[derive(Debug)] pub struct Resource { - byte_map: HashMap>, value_map: HashMap, } @@ -59,14 +58,7 @@ impl Resource { info!("finish preload"); } } - Ok(Self { - byte_map, - value_map, - }) - } - - pub fn get_bytes(&self, key: &usize) -> Option<&[u8]> { - self.byte_map.get(key).map(|v| &v[..]) + Ok(Self { value_map }) } pub fn get_value(&self, key: &usize) -> Option<&Value> {