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.

§Example

impl ParseDocument<'_> for User {
    fn parse(doc: &EureDocument, node_id: NodeId) -> Result<Self, ParseError> {
        let mut rec = doc.parse_record(node_id)?;
        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 field<T: ParseDocument<'doc>>( &mut self, name: &str, ) -> Result<T, ParseError>

Get a required field.

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

Source

pub fn field_optional<T: ParseDocument<'doc>>( &mut self, name: &str, ) -> Result<Option<T>, ParseError>

Get an optional field.

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

Source

pub fn field_node(&mut self, name: &str) -> Result<NodeId, ParseError>

Get the NodeId for a field (for manual handling).

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

Source

pub fn field_node_optional(&mut self, name: &str) -> Option<NodeId>

Get the NodeId for an optional field.

Returns 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.

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, NodeId)> + '_

Get an iterator over unknown fields (for Schema policy or custom handling).

Returns (field_name, node_id) pairs for fields that haven’t been accessed.

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.