pub struct ContextView<'a> { /* private fields */ }Expand description
The runtime types that appear in bevy-brink’s own public signatures,
re-exported so consumers can name them without depending on brink-runtime:
FlowInstance, Program,
Choice, Step’s
return, RuntimeError’s error,
FallbackHandler for the “no bindings” advance path, the scoped
story-state types a host needs to build a policy and a per-step routing
view (see docs/scoped-flow-state-spec.md): WorldPolicy, Scope,
PolicyError, and ContextView (usually built via
flow_context_view instead of by hand) — and the per-entity durability
types produced/consumed by BrinkGlobals::save_state/load_state and
save_flow_state/load_flow_state (F6.3, see the globals module’s
“Save/load” docs): SaveState and LoadReport.
World is deliberately absent here — it collides with bevy::prelude::World
under a glob import, so it is re-exported under the alias BrinkWorld.
Routing view implementing ContextAccess over (&mut World, &mut FlowLocal).
This is what the VM’s drive path receives as its impl ContextAccess.
Every op computes an effective scope for its unit — see
ContextView::effective_scope — and then routes exactly as before:
World-scoped: always routes straight toWorld— reads and writes are immediately visible to every flow sharing thatWorld.Local-scoped, read: chain read-through — walks theFlowLocal’s own overrides, then its frozenbase(recursively, seeFlowLocal::chain_get_globaland friends), then falls back toWorld’s current value on a total miss (so a flow that has never written a Local unit, nor inherited one from a base, sees the shared default until its first local write).Local-scoped, write: lands in theFlowLocal’s own top-layer overrides only;World(and any frozenbase) is untouched.Local-scoped, increment (increment_visit,increment_turn_index): copy-on-write from the chain read-through value — read the current value (own override, else base chain, else World fallback), add one, store the result as the new top-layer override. This is what makes a flow’s first local increment start from the chain’s (or World’s) count rather than 0.
The effective scope, not the raw policy scope, drives all of the
above. In Mode::Normal (every construction path before F3.2, and
every non-forked flow today) the effective scope of a unit is its
ResolvedPolicy scope — unchanged from F2.2/F3.1. In Mode::Sandbox
the effective scope of every unit is Local, no matter what the
policy says: a sandboxed flow’s reads still chain-read-through to
World’s live value on a miss (so it observes current shared state),
but its writes — including to units the policy homes to World — land
only in its own FlowLocal overrides. World is therefore a read-only
base from a sandboxed flow’s perspective: nothing it does can mutate the
shared world.
Because the all-World policy (the only policy the oracle corpus
exercises) takes the World branch on every op and no existing
construction path ever sets Mode::Sandbox, this is byte-identical to
the F1.3 all-World passthrough for every existing single-flow
construction path.
Implementations§
Source§impl<'a> ContextView<'a>
impl<'a> ContextView<'a>
Sourcepub fn new(world: &'a mut World, local: &'a mut FlowLocal) -> ContextView<'a>
pub fn new(world: &'a mut World, local: &'a mut FlowLocal) -> ContextView<'a>
Build a routing view over a World and FlowLocal pair for the
duration of one step.
Trait Implementations§
Source§impl ContextAccess for ContextView<'_>
impl ContextAccess for ContextView<'_>
Source§fn take_global(&mut self, idx: u32) -> Value
fn take_global(&mut self, idx: u32) -> Value
World-scoped units (the all-World default policy every oracle
program runs under) delegate straight to World::take_global’s real
move. Local-scoped units use the trait’s default clone-then-null:
a real move only helps when this flow already owns the unique
reference, which the read-through chain (own overrides → frozen
base → World) can’t generally provide — an immutable
[FrozenLocal] ancestor can’t be moved out of. Own-layer overrides
(self.local.globals) could be moved out of directly, but the
perf-critical path this closes (value-model-spec §5’s loop-append
cliff) is the common single-World case; a Local-scoped fast path
is future work if profiling ever shows it matters (T1b-4/#576 scope
note).
fn global(&self, idx: u32) -> &Value
fn set_global(&mut self, idx: u32, value: Value)
fn visit_count(&self, id: DefinitionId) -> u32
fn increment_visit(&mut self, id: DefinitionId)
Source§fn set_visit_count(&mut self, id: DefinitionId, count: u32)
fn set_visit_count(&mut self, id: DefinitionId, count: u32)
crate::load_state to reconcile a durable save, whose entries carry
absolute counts rather than deltas.fn turn_count(&self, id: DefinitionId) -> Option<u32>
fn set_turn_count(&mut self, id: DefinitionId, turn: u32)
fn turn_index(&self) -> u32
fn increment_turn_index(&mut self)
Source§fn set_turn_index(&mut self, index: u32)
fn set_turn_index(&mut self, index: u32)
crate::load_state to restore a saved turn index.fn rng_seed(&self) -> i32
fn set_rng_seed(&mut self, seed: i32)
fn previous_random(&self) -> i32
fn set_previous_random(&mut self, val: i32)
fn next_random<R>(&self, seed: i32) -> i32where
R: StoryRng,
fn random_sequence<R>(&self, seed: i32, count: usize) -> Vec<i32>where
R: StoryRng,
Auto Trait Implementations§
impl<'a> !UnwindSafe for ContextView<'a>
impl<'a> Freeze for ContextView<'a>
impl<'a> RefUnwindSafe for ContextView<'a>
impl<'a> Send for ContextView<'a>
impl<'a> Sync for ContextView<'a>
impl<'a> Unpin for ContextView<'a>
impl<'a> UnsafeUnpin for ContextView<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.