pub struct NestedListFieldExtractor { /* private fields */ }Expand description
Extracts a list of scalar values from a nested Vec<T> field using a path.
This enables FanOut-style extraction for lists within nested structures.
§Example
use serde::Serialize;
use serde_evaluate::{NestedListFieldExtractor, FieldScalarValue, EvaluateError};
#[derive(Serialize)]
struct Record {
metadata: Metadata,
}
#[derive(Serialize)]
struct Metadata {
labels: Vec<String>,
}
fn main() -> Result<(), EvaluateError> {
let record = Record {
metadata: Metadata {
labels: vec!["label1".to_string(), "label2".to_string()],
},
};
let extractor = NestedListFieldExtractor::new_from_path(&["metadata", "labels"])?;
let values = extractor.evaluate(&record)?;
assert_eq!(values, vec![
FieldScalarValue::String("label1".to_string()),
FieldScalarValue::String("label2".to_string()),
]);
Ok(())
}Implementations§
Source§impl NestedListFieldExtractor
impl NestedListFieldExtractor
Sourcepub fn new_from_path<S: AsRef<str>>(
path_segments: &[S],
) -> Result<Self, EvaluateError>
pub fn new_from_path<S: AsRef<str>>( path_segments: &[S], ) -> Result<Self, EvaluateError>
Creates a new NestedListFieldExtractor from a slice of path segments.
Each element in the input slice represents a step in the path.
§Arguments
path_segments: A slice where each element can be converted into a&str(e.g.,&str,String).
§Errors
Returns EvaluateError::InvalidPath if the input slice is empty or if any
segment converts to an empty string.
Sourcepub fn evaluate<T: Serialize>(
&self,
value: &T,
) -> Result<Vec<FieldScalarValue>, EvaluateError>
pub fn evaluate<T: Serialize>( &self, value: &T, ) -> Result<Vec<FieldScalarValue>, EvaluateError>
Extracts all scalar elements from a nested Vec<T> field.
§Arguments
value- A reference to a value that implementsserde::Serialize.
§Returns
Ok(Vec<FieldScalarValue>)containing each element as a scalar value.Ok(vec![])for empty lists orOption<Vec<T>>withNone.
§Errors
Returns EvaluateError if:
- The path is not found (
EvaluateError::NestedFieldNotFound). - The list elements are not scalar types (
EvaluateError::UnsupportedType).
Trait Implementations§
Source§impl Clone for NestedListFieldExtractor
impl Clone for NestedListFieldExtractor
Source§fn clone(&self) -> NestedListFieldExtractor
fn clone(&self) -> NestedListFieldExtractor
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for NestedListFieldExtractor
impl RefUnwindSafe for NestedListFieldExtractor
impl Send for NestedListFieldExtractor
impl Sync for NestedListFieldExtractor
impl Unpin for NestedListFieldExtractor
impl UnwindSafe for NestedListFieldExtractor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more