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: EngineImplementations§
Source§impl<'d> Ctx<'d>
impl<'d> Ctx<'d>
pub fn new(engine: Engine, diag: &'d mut dyn DiagSink) -> Self
Sourcepub fn reborrow(&mut self) -> Ctx<'_>
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.
Sourcepub fn report(
&mut self,
struct_name: &'static str,
chunk_id: u32,
offset: u32,
kind: DiagKind,
)
pub fn report( &mut self, struct_name: &'static str, chunk_id: u32, offset: u32, kind: DiagKind, )
Record a recoverable problem.
Sourcepub fn should_abort(&self) -> bool
pub fn should_abort(&self) -> bool
Whether the sink has asked parsing to stop (strict mode).
Sourcepub fn latched(&self) -> Option<Diagnostic>
pub fn latched(&self) -> Option<Diagnostic>
The latched diagnostic, if the sink latches one.