pub struct FieldExtractor { /* private fields */ }Expand description
Facilitates the extraction of a scalar value from a specified field within a Serializeable struct.
This struct holds the configuration for the extraction, namely the target field name.
The primary way to use this is via the associated function FieldExtractor::evaluate.
Implementations§
Source§impl FieldExtractor
impl FieldExtractor
Sourcepub fn new<S: Into<String>>(field_name: S) -> Self
pub fn new<S: Into<String>>(field_name: S) -> Self
Creates a new FieldExtractor configured to target the specified field name.
Accepts any type that can be converted into a String, such as &str.
Sourcepub fn evaluate<T: Serialize>(
&self,
record: &T,
) -> Result<FieldScalarValue, EvaluateError>
pub fn evaluate<T: Serialize>( &self, record: &T, ) -> Result<FieldScalarValue, EvaluateError>
Extracts the scalar value of the configured field_name from the given record.
This method drives the custom serialization process to capture the field’s value.
§Arguments
record: A reference to a struct that implementsserde::Serialize.
§Errors
Returns EvaluateError if:
- The
field_nameis not found in therecord(EvaluateError::FieldNotFound). - The
field_name’s value is not a supported scalar type (EvaluateError::UnsupportedType). - Any other Serde serialization error occurs.
Trait Implementations§
Source§impl Clone for FieldExtractor
impl Clone for FieldExtractor
Source§fn clone(&self) -> FieldExtractor
fn clone(&self) -> FieldExtractor
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 FieldExtractor
impl RefUnwindSafe for FieldExtractor
impl Send for FieldExtractor
impl Sync for FieldExtractor
impl Unpin for FieldExtractor
impl UnwindSafe for FieldExtractor
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