Skip to main content

Module structural_visit

Module structural_visit 

Source
Expand description

Native Rust structural visiting.

Two public layers:

  • Dispatcher + structural_visit — handlers drive recursion through an explicit StructuralVisitorView context. Pass state belongs on the dispatcher; visitor.visit(self, &child) reborrows it for recursive calls. Unmatched values use default child traversal.
  • structural_walk — dispatcher or closure observers steer engine-owned recursion through WalkResult (advance, skip, interrupt).

Both layers thread definition-region state explicitly. Walk handlers opt in with a trailing DefRegionKind; visit handlers read it from their context and may override it for a child through StructuralVisitorView::with_def_region_kind.

§Safety of the implementation

The public interface is safe; its implementation deliberately uses raw pointers. Each private runtime has a matching dispatcher vtable and a fixed dispatcher identity. The dispatcher stays alive in the outer call, and the engine’s dispatcher pointer publishes the actual exclusive reborrow before native recursion, then restores the enclosing borrow on return. Views and native runtime handles cannot escape their synchronous calls. No reference to the whole runtime spans recursion, and owning ABI results transfer exactly one reference at each boundary.

Callbacks must return failures through Result and must not panic. A panic reaching the non-unwinding extern "C" callback boundary aborts the process; visitor callbacks do not catch or transport panic payloads across native frames.

Structs§

StructuralVisitEngine
Scoped Rust visitor runtime with a statically selected native base.
StructuralVisitorObj
The native visitor state, laid out as the prefix of the C++ StructuralVisitorObj.
StructuralVisitorView
The running structural visit, passed to each handler.
VisitInterrupt
Interrupt state of a traversal, an ffi.VisitInterrupt object.
VisitInterruptObj
Native ffi.VisitInterrupt object containing the interruption payload.

Enums§

DefRegionKind
Definition-region state active at the current value.

Traits§

StructuralVisitorBase
Native state and default traversal for StructuralVisitEngine. The engine owns allocation, scoped dispatch and results.

Functions§

structural_visit
Visit root with an owned or borrowed Dispatcher.