pub struct RecordParser<'doc> { /* private fields */ }Expand description
Helper for parsing record (map with string keys) from Eure documents.
Tracks accessed fields for unknown field checking.
§Flatten Context
When flatten_ctx is Some, this parser is part of a flattened chain:
- Field accesses are recorded in the shared
FlattenContext deny_unknown_fields()is a no-op (root parser validates)
When flatten_ctx is None, this is a root parser:
- Field accesses are recorded in local
accessedset deny_unknown_fields()actually validates
§Example
impl<'doc> ParseDocument<'doc> for User {
fn parse(ctx: &ParseContext<'doc>) -> Result<Self, ParseError> {
let mut rec = ctx.parse_record()?;
let name = rec.field::<String>("name")?;
let age = rec.field_optional::<u32>("age")?;
rec.deny_unknown_fields()?;
Ok(User { name, age })
}
}Implementations§
Source§impl<'doc> RecordParser<'doc>
impl<'doc> RecordParser<'doc>
Sourcepub fn parse_field<T>(&self, name: &str) -> Result<T, T::Error>
pub fn parse_field<T>(&self, name: &str) -> Result<T, T::Error>
Get a required field.
Returns ParseErrorKind::MissingField if the field is not present or is excluded.
pub fn parse_field_with<T>( &self, name: &str, parser: T, ) -> Result<T::Output, T::Error>
pub fn parse_field_optional<T>(&self, name: &str) -> Result<Option<T>, T::Error>
Sourcepub fn parse_field_optional_with<T>(
&self,
name: &str,
parser: T,
) -> Result<Option<T::Output>, T::Error>
pub fn parse_field_optional_with<T>( &self, name: &str, parser: T, ) -> Result<Option<T::Output>, T::Error>
Get an optional field.
Returns Ok(None) if the field is not present.
Sourcepub fn field(&self, name: &str) -> Result<ParseContext<'doc>, ParseError>
pub fn field(&self, name: &str) -> Result<ParseContext<'doc>, ParseError>
Get the parse context for a field without parsing it.
Use this when you need access to the field’s NodeId or want to defer parsing.
Returns ParseErrorKind::MissingField if the field is not present.
Sourcepub fn field_optional(&self, name: &str) -> Option<ParseContext<'doc>>
pub fn field_optional(&self, name: &str) -> Option<ParseContext<'doc>>
Get the parse context for an optional field without parsing it.
Use this when you need access to the field’s NodeId or want to defer parsing.
Returns None if the field is not present.
Sourcepub fn field_record(&self, name: &str) -> Result<RecordParser<'doc>, ParseError>
pub fn field_record(&self, name: &str) -> Result<RecordParser<'doc>, ParseError>
Get a field as a nested record parser.
Returns ParseErrorKind::MissingField if the field is not present.
Sourcepub fn field_record_optional(
&self,
name: &str,
) -> Result<Option<RecordParser<'doc>>, ParseError>
pub fn field_record_optional( &self, name: &str, ) -> Result<Option<RecordParser<'doc>>, ParseError>
Get an optional field as a nested record parser.
Returns Ok(None) if the field is not present.
Sourcepub fn deny_unknown_fields(self) -> Result<(), ParseError>
pub fn deny_unknown_fields(self) -> Result<(), ParseError>
Finish parsing with Deny policy (error if unknown fields exist).
This also errors if the map contains non-string keys, as records should only have string-keyed fields.
Flatten behavior: If this parser has a flatten_ctx (i.e., is a child in a flatten chain), this is a no-op. Only root parsers validate.
Sourcepub fn allow_unknown_fields(self) -> Result<(), ParseError>
pub fn allow_unknown_fields(self) -> Result<(), ParseError>
Finish parsing with Allow policy (allow unknown string fields).
This still errors if the map contains non-string keys, as records should only have string-keyed fields.
Sourcepub fn unknown_fields(
&self,
) -> impl Iterator<Item = (&'doc str, ParseContext<'doc>)> + '_
pub fn unknown_fields( &self, ) -> impl Iterator<Item = (&'doc str, ParseContext<'doc>)> + '_
Get an iterator over unknown fields (for Schema policy or custom handling).
Returns (field_name, context) pairs for fields that haven’t been accessed.
Sourcepub fn flatten(&self) -> ParseContext<'doc>
pub fn flatten(&self) -> ParseContext<'doc>
Create a flatten context for child parsers in Record scope.
This creates a FlattenContext initialized with the current accessed fields, and returns a ParseContext that children can use. Children created from this context will:
- Add their accessed fields to the shared FlattenContext
- Have deny_unknown_fields() be a no-op
The root parser should call deny_unknown_fields() after all children are done.