Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx<'d> {
    pub engine: Engine,
    /* private fields */
}
Expand description

Parse-time context threaded through every read: the target engine, and where to report recoverable problems.

It also carries the string-list entry budget for the load. Reuse one Ctx across several loads and they share what the earlier ones left, so a fresh Ctx per load is the usual pattern.

The sink is dyn on purpose: diagnostics are the cold path, so the indirect call is free in practice, while monomorphising ~70 generated read methods per sink type would bloat code. marshal-rs makes the same trade for its symbol table.

Fields§

§engine: Engine

Implementations§

Source§

impl<'d> Ctx<'d>

Source

pub fn new(engine: Engine, diag: &'d mut dyn DiagSink) -> Self

Source

pub fn reborrow(&mut self) -> Ctx<'_>

Reborrow for a nested struct.

Schema depth is fixed by the format (four levels at most: Database -> Troop -> TroopPage -> EventCommand), so recursive descent is safe. It would not be for an attacker-controlled shape.

Source

pub fn report( &mut self, struct_name: &'static str, chunk_id: u32, offset: u32, kind: DiagKind, )

Record a recoverable problem.

Source

pub fn should_abort(&self) -> bool

Whether the sink has asked parsing to stop (strict mode).

Source

pub fn latched(&self) -> Option<Diagnostic>

The latched diagnostic, if the sink latches one.

Trait Implementations§

Source§

impl Debug for Ctx<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'d> !RefUnwindSafe for Ctx<'d>

§

impl<'d> !Send for Ctx<'d>

§

impl<'d> !Sync for Ctx<'d>

§

impl<'d> !UnwindSafe for Ctx<'d>

§

impl<'d> Freeze for Ctx<'d>

§

impl<'d> Unpin for Ctx<'d>

§

impl<'d> UnsafeUnpin for Ctx<'d>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.