pub struct FlowLocal { /* private fields */ }Expand description
Per-flow override layer over the shared World.
F3.1: copy-on-write, frozen-base read-through chain. Each field is a
plain map/option holding this flow’s own overrides for units
ResolvedPolicy homes to Scope::Local (or, in Mode::Sandbox,
every unit — see Mode), plus an optional base: an immutable
[FrozenLocal] snapshot (see FlowLocal::freeze) of another
FlowLocal, captured at some earlier point. A read walks own
overrides → base (recursively) → [miss]; ContextView treats a miss
as “not in the local chain” and falls through to World, exactly as in
F2.2. Writes always land in the flow’s own top-layer overrides — never
in base, which is immutable by construction.
A fresh FlowLocal (via Default/FlowLocal::new) has empty
overrides, base: None, and mode: Mode::Normal, so it contributes no
reads and every access falls through to World — this is what keeps the
all-World policy (and every construction path that doesn’t call
fork) byte-identical to the F2.2 flat-storage behavior.
FlowLocal::fork (F3.2) is what actually populates a child’s base by
freezing its parent, and what bakes in a non-Normal mode.
ContextView (below) is what actually consults these maps; see its
docs for the read-through/copy-on-write-increment/mode semantics.
Implementations§
Source§impl FlowLocal
impl FlowLocal
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty flow-local layer — overrides nothing and has no
base, so every access routes through to World.
Sourcepub fn fork(&self, mode: Mode) -> FlowLocal
pub fn fork(&self, mode: Mode) -> FlowLocal
Fork a child FlowLocal from this one.
The child’s base is a frozen, point-in-time snapshot of self (via
freeze) — an O(1)-ish operation that clones this
flow’s own (small) override maps and Arc-bumps the rest of the
ancestry chain, never a full World copy. The child’s own override
layer starts empty, and it runs in mode for its lifetime (Mode is
baked in here, not mutable afterward).
Because the base is frozen, later mutations to self (the parent)
are not visible to the child — the child sees the parent exactly
as it was at fork time. Symmetrically, nothing the child does is ever
visible to self or World: writes land only in the child’s own top
layer (see Mode for how Sandbox additionally diverts
World-scoped writes there too). That makes discard trivial —
dropping the returned FlowLocal is the entire discard operation, no
unwinding required. Folding a child’s writes back into self instead
of discarding them is the deferred commit seam — see CommitError
and commit.