ExtParser

Struct ExtParser 

Source
pub struct ExtParser<'doc> { /* private fields */ }
Expand description

Helper for parsing extension types ($ext-type) from Eure documents.

Similar API to RecordParser but for extension type fields.

§Example

let mut ext = doc.parse_extension(node_id);
let optional = ext.field_optional::<bool>("optional")?;
let binding_style = ext.field_optional::<BindingStyle>("binding-style")?;
ext.allow_unknown_fields()?;

Implementations§

Source§

impl<'doc> ExtParser<'doc>

Source

pub fn node_id(&self) -> NodeId

Get the node ID being parsed.

Source

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

Get a required extension field.

Returns ParseErrorKind::MissingExtension if the extension is not present.

Source

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

Get an optional extension field.

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

Source

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

Get the NodeId for an extension field (for manual handling).

Returns ParseErrorKind::MissingExtension if the extension is not present.

Source

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

Get the NodeId for an optional extension field.

Returns None if the extension is not present.

Source

pub fn deny_unknown_extensions(self) -> Result<(), ParseError>

Finish parsing with Deny policy (error if unknown extensions exist).

Source

pub fn allow_unknown_extensions(self)

Finish parsing with Allow policy (ignore unknown extensions).

Source

pub fn unknown_extensions( &self, ) -> impl Iterator<Item = (&'doc Identifier, NodeId)> + '_

Get an iterator over unknown extensions (for custom handling).

Returns (identifier, node_id) pairs for extensions that haven’t been accessed.

Auto Trait Implementations§

§

impl<'doc> Freeze for ExtParser<'doc>

§

impl<'doc> RefUnwindSafe for ExtParser<'doc>

§

impl<'doc> Send for ExtParser<'doc>

§

impl<'doc> Sync for ExtParser<'doc>

§

impl<'doc> Unpin for ExtParser<'doc>

§

impl<'doc> UnwindSafe for ExtParser<'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.