21 lines
513 B
Rust
21 lines
513 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) -> 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())
|
|
}
|
|
}
|