RecordParser

Struct RecordParser 

Source
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 accessed set
  • 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>

Source

pub fn node_id(&self) -> NodeId

Get the node ID being parsed.

Source

pub fn parse_field<T>(&self, name: &str) -> Result<T, T::Error>
where T: ParseDocument<'doc>, T::Error: From<ParseError>,

Get a required field.

Returns ParseErrorKind::MissingField if the field is not present or is excluded.

Source

pub fn parse_field_with<T>( &self, name: &str, parser: T, ) -> Result<T::Output, T::Error>
where T: DocumentParser<'doc>, T::Error: From<ParseError>,

Source

pub fn parse_field_optional<T>(&self, name: &str) -> Result<Option<T>, T::Error>
where T: ParseDocument<'doc>, T::Error: From<ParseError>,

Source

pub fn parse_field_optional_with<T>( &self, name: &str, parser: T, ) -> Result<Option<T::Output>, T::Error>
where T: DocumentParser<'doc>, T::Error: From<ParseError>,

Get an optional field.

Returns Ok(None) if the field is not present.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'doc> Freeze for RecordParser<'doc>

§

impl<'doc> !RefUnwindSafe for RecordParser<'doc>

§

impl<'doc> !Send for RecordParser<'doc>

§

impl<'doc> !Sync for RecordParser<'doc>

§

impl<'doc> Unpin for RecordParser<'doc>

§

impl<'doc> !UnwindSafe for RecordParser<'doc>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.