Skip to main content

TupData

Struct TupData 

Source
pub struct TupData<D, M> { /* private fields */ }
Available on crate features unstable-features only.
Expand description

Utility for saving intermediate values.

Complex parsing tools usually use several other tools to perform to perform simple subtasks. However, dealing with many of these tools makes harder to keep consistent both returned data and the total length of the match, which we remember should be consistent with the number of bytes skipped by the View object.

This object keeps an instance of intermediate returned data, actual number of bytes skipped and the last instance of View, keeping them consistent.

Implementations§

Source§

impl<D, M> TupData<D, M>

Source

pub fn new(this: M) -> Self
where D: Default,

Creates a new instance of this object.

Source

pub fn map_data<DD, F: FnOnce(D) -> DD>(self, f: F) -> TupData<DD, M>

Applies a function to the saved data without modifying other fields.

Source

pub fn get_data(self) -> (D, TupData<(), M>)

Moves stored data outside.

Source

pub fn finalize(self) -> (D, usize, M)

Unpack this objects and returns all its fields.

Source§

impl<'a, D> TupData<D, View<'a>>

Source

pub fn chain_replace<T>( self, t: &T, ) -> Result<TupData<T::Data, View<'a>>, T::Error>
where T: Tool<'a>,

Match a Tool and replace stored data with returned data.

Source

pub fn chain_nodata<T>(self, t: &T) -> Result<Self, T::Error>
where T: Tool<'a>,

Match a Tool but discards returned data.

Source

pub fn chain_save<T>( self, t: &T, ) -> Result<TupData<(D, T::Data), View<'a>>, T::Error>
where T: Tool<'a>,

Match a Tool and keeps both saved and returned data.

Source

pub fn chain_save_out<T>(self, t: &T) -> Result<(Self, T::Data), T::Error>
where T: Tool<'a>,

Match a Tool and keeps returned data separated from original data.

Source

pub fn chain_save_at<T>(self, t: &T, to: &mut T::Data) -> Result<Self, T::Error>
where T: Tool<'a>,

Match a Tool and saves returned data at a different location.

Source§

impl<'a> TupData<(), View<'a>>

Source

pub fn chain<T>(self, t: &T) -> Result<TupData<T::Data, View<'a>>, T::Error>
where T: Tool<'a>,

Match a Tool object.

Trait Implementations§

Source§

impl<D: Clone, M: Clone> Clone for TupData<D, M>

Source§

fn clone(&self) -> TupData<D, M>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: Debug, M: Debug> Debug for TupData<D, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<D: PartialEq, M: PartialEq> PartialEq for TupData<D, M>

Source§

fn eq(&self, other: &TupData<D, M>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D: Copy, M: Copy> Copy for TupData<D, M>

Source§

impl<D: Eq, M: Eq> Eq for TupData<D, M>

Source§

impl<D, M> StructuralPartialEq for TupData<D, M>

Auto Trait Implementations§

§

impl<D, M> Freeze for TupData<D, M>
where D: Freeze, M: Freeze,

§

impl<D, M> RefUnwindSafe for TupData<D, M>

§

impl<D, M> Send for TupData<D, M>
where D: Send, M: Send,

§

impl<D, M> Sync for TupData<D, M>
where D: Sync, M: Sync,

§

impl<D, M> Unpin for TupData<D, M>
where D: Unpin, M: Unpin,

§

impl<D, M> UnsafeUnpin for TupData<D, M>
where D: UnsafeUnpin, M: UnsafeUnpin,

§

impl<D, M> UnwindSafe for TupData<D, M>
where D: UnwindSafe, M: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.