29 lines
590 B
Rust
29 lines
590 B
Rust
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,
|
|
args: Option<&str>,
|
|
) -> Result<Option<PileValue>, std::io::Error> {
|
|
if args.is_some() {
|
|
return Ok(None);
|
|
}
|
|
|
|
Ok(self.inner.get(name).cloned())
|
|
}
|
|
|
|
async fn fields(&self) -> Result<Vec<Label>, std::io::Error> {
|
|
Ok(self.inner.keys().cloned().collect())
|
|
}
|
|
}
|