Skip to main content

ContextView

Struct ContextView 

Source
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 to World — reads and writes are immediately visible to every flow sharing that World.
  • Local-scoped, read: chain read-through — walks the FlowLocal’s own overrides, then its frozen base (recursively, see FlowLocal::chain_get_global and friends), then falls back to World’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 the FlowLocal’s own top-layer overrides only; World (and any frozen base) 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>

Source

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<'_>

Source§

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).

Source§

fn global(&self, idx: u32) -> &Value

Source§

fn set_global(&mut self, idx: u32, value: Value)

Source§

fn visit_count(&self, id: DefinitionId) -> u32

Source§

fn increment_visit(&mut self, id: DefinitionId)

Source§

fn set_visit_count(&mut self, id: DefinitionId, count: u32)

Set a visit count directly, rather than incrementing it. Used by crate::load_state to reconcile a durable save, whose entries carry absolute counts rather than deltas.
Source§

fn turn_count(&self, id: DefinitionId) -> Option<u32>

Source§

fn set_turn_count(&mut self, id: DefinitionId, turn: u32)

Source§

fn turn_index(&self) -> u32

Source§

fn increment_turn_index(&mut self)

Source§

fn set_turn_index(&mut self, index: u32)

Set the turn index directly, rather than incrementing it. Used by crate::load_state to restore a saved turn index.
Source§

fn rng_seed(&self) -> i32

Source§

fn set_rng_seed(&mut self, seed: i32)

Source§

fn previous_random(&self) -> i32

Source§

fn set_previous_random(&mut self, val: i32)

Source§

fn next_random<R>(&self, seed: i32) -> i32
where R: StoryRng,

Source§

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> 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> ConditionalSend for T
where T: Send,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Lookup<T> for T

Source§

fn into_owned(self) -> T

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more