Extractor rewrite
This commit is contained in:
20
crates/pile-value/src/extract/misc/map.rs
Normal file
20
crates/pile-value/src/extract/misc/map.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use pile_config::Label;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{extract::traits::ObjectExtractor, value::PileValue};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MapExtractor {
|
||||
pub inner: HashMap<Label, PileValue>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ObjectExtractor for MapExtractor {
|
||||
async fn field(&self, name: &Label) -> Result<Option<PileValue>, std::io::Error> {
|
||||
Ok(self.inner.get(name).cloned())
|
||||
}
|
||||
|
||||
async fn fields(&self) -> Result<Vec<Label>, std::io::Error> {
|
||||
Ok(self.inner.keys().cloned().collect())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user