Skip to main content

Scope

Struct Scope 

Source
pub struct Scope { /* private fields */ }
Expand description

Where a segment’s state, features and resources live, from the moment it is installed until it is removed.

A name for one, and Copy: the ScopeTree it is in owns what each scope holds, and nothing else does. Holding a Scope does not keep it alive, so a scope goes exactly when remove is called on it or on a scope above it - children first - or when its tree’s owner lets go of the tree, and not whenever the last of whoever happened to be holding it lets go.

A removed scope’s name never comes back: every scope is numbered once, so an old Scope keeps naming the scope that is gone, and is_alive says so.

Implementations§

Source§

impl Scope

Source

pub fn set_window(&self, id: u64)

Says this scope is the root of window id, as RootId::get numbers it: what devtools are told the actors under it belong to.

Source

pub fn window(&self) -> Option<u64>

The window this scope is under, if it is under one.

Source

pub fn hold_actor<A: ManagedActor + Debug>( &self, addr: &Addr<A>, feature: Option<&'static str>, drives: Option<&'static str>, )

Lists addr among the actors this scope holds, for devtools, until the scope is removed - feature created it, and it drives drives when it was made to.

Only the listing: what ends the actor is still whoever owns it, which for an actor of a segment is own on this same scope.

Source

pub fn actors(&self) -> Vec<ActorSnapshot>

The actors this scope and every scope under it hold, read now.

Source

pub fn actor(&self, id: usize) -> Option<ActorSnapshot>

The actor id, if this scope or one under it holds it, read now; the others are not read.

Source

pub fn actors_here(&self) -> Vec<ActorSnapshot>

The actors this scope holds itself, read now - not those of the scopes under it.

Source

pub fn actor_here(&self, id: usize) -> Option<ActorSnapshot>

The actor id, if this scope holds it itself, read now.

Source§

impl Scope

Source

pub fn mark_feature_installed<F: 'static>(&self)

Marks feature F (its install function, used purely as a type identity) as owned by this scope. F must not already be marked here - two different call sites both claiming ownership of the same feature in the same scope is a setup bug, not something to merge silently.

Source

pub fn claims<R: 'static>(&self) -> bool

Whether anything in this scope has claimed R.

What tells an export that was earned from one that was only declared.

Source

pub fn note_reducer_owner<R: 'static>(&self)

Source

pub fn note_reducer_declared<R: 'static>(&self, declared: Declared)

Notes where reducer R was claimed, the first claim winning.

Source

pub fn current_crate_dir(&self) -> Option<&'static str>

The manifest directory of the feature installing now, for a claim that only knows the file the compiler gave it.

Source

pub fn open_section( &self, name: Option<&'static str>, declared: Option<Declared>, ) -> usize

Opens a section for what is about to install - the feature name, or something that is not a feature, such as a plugin. Returns its index.

Source

pub fn section_name(&self, section: usize) -> Option<&'static str>

The feature a section belongs to; None for the segment’s own.

Source

pub fn features(&self) -> Vec<Installed>

Every feature installed here, in the order they were.

Source

pub fn current_feature(&self) -> Option<&'static str>

The feature being installed right now, if any.

Source

pub fn note_listener( &self, event: &'static str, actor: Option<&'static str>, bus: Bus, )

Notes that whatever is installing listens to event on bus - through actor when an actor does the listening.

Source

pub fn listeners(&self) -> Vec<Listener>

Source

pub fn close_section(&self)

Source

pub fn current_section(&self) -> usize

The section being installed, or the segment’s own when none is.

Source

pub fn section_of<R: 'static>(&self) -> usize

Which section owns R - the instance whose dispatcher a reader of R should be handed.

Source

pub fn has_feature<F: 'static>(&self) -> bool

Whether feature F was marked installed in this exact scope.

Source

pub fn note_export<R: 'static>(&self)

Marks R as readable from segments below this one.

Called by cx.install::<F>() for everything in F::Exports, and by an application’s export::<R>(). A reducer a feature claimed but did not export stays visible to the feature itself and invisible from below - which is the whole difference between a feature and a folder.

Source

pub fn exports<R: 'static>(&self) -> bool

Whether R is readable from below this scope.

Source

pub fn answers<M: 'static>(&self, answer: impl Fn(M) + 'static)

Says that this scope answers M, and how.

Keyed by the action, not by whoever answers it - which is what keeps the answerer out of every signature the UI touches. actor! calls this for each handler it lists; a domain that runs on tasks, or a channel, or a plain closure over a RefCell, calls it itself.

Source

pub fn answerer<M: 'static>(&self, section: usize) -> Option<Rc<dyn Fn(M)>>

What answers M in one section of this scope, if anything does.

Source

pub fn first_answerer<M: 'static>(&self) -> Option<Rc<dyn Fn(M)>>

What answers M anywhere in this scope - the first feature that does, in the order they installed. For a sender that knows the action and not which state it was reading.

Source§

impl Scope

Source

pub fn own_subscription(&self, subscription: BusSubscription)

Source

pub fn own<R: Teardown>(&self, resource: R)

Binds any Teardown resource to this scope’s lifetime: it is torn down when the scope is - at once, if the scope is already gone.

Source

pub fn on_leave(&self, guard: impl Fn() -> Verdict + 'static)

Asked before this scope is torn down by a navigation.

Registered during install, which is the whole reason leaving and entering are declared in different places: on the way out the scope exists, so the guard can read its own state - which is what “unsaved changes” is. On the way in there is nothing to read yet.

Source

pub fn leave_guards(&self) -> Vec<Rc<dyn Fn() -> Verdict>>

The guards to ask, in the order they were registered.

Cloned out rather than borrowed: a guard is free to touch this scope, and the caller runs them while deciding.

Source

pub fn sleep(&self)

Puts this scope to sleep: kept, with its state and actors, but deaf.

What it owns stops hearing anything while it sleeps - its timers skip their ticks, its actors and callbacks are not told what the buses carry - and nothing is queued for later: what happened meanwhile is missed. A router does this to a keep segment it leaves.

Source

pub fn wake(&self)

Wakes this scope, then runs what asked to hear of it, in the order it asked.

Source

pub fn is_awake(&self) -> bool

Whether this scope is there and awake. A removed one is neither.

Source

pub fn awake(&self) -> Awake

Whether this scope is awake, for what it owns to ask later.

Source

pub fn on_wake(&self, hook: impl Fn() + 'static)

Runs hook every time this scope wakes: for a feature to catch up on what it missed while it slept.

Source§

impl Scope

Source

pub fn describe_states(&self) -> Vec<DescribedState>

Every reducer this scope holds whose type it has seen, printed.

Source

pub fn state<R: Reducer>(&self) -> Rc<Slot<R>>

R’s state here, created from R::default() on first read.

A removed scope has no state to hand out: what comes back is a fresh default nobody else sees.

Source

pub fn peek<R: Reducer>(&self) -> Option<Rc<Slot<R>>>

Source

pub fn seed<R: Reducer>(&self, state: R)

Sets R’s starting value instead of R::default(). Call before anything else touches R in this scope - overwrites any existing cell, dropping its listeners.

Source

pub fn push<R: Reducer>(&self, update: R::Update)

Applies msg to F’s state now, and marks the cell so its listeners run at the next notify::drain.

The state is current the moment this returns; what waits is the redraw. Nothing a listener does - navigating, dropping scopes, sending to another actor - happens on the stack of whoever pushed. A no-op once the scope is removed.

Source

pub fn observe<R: Reducer>( &self, callback: impl Fn(&R::Update) + 'static, ) -> Subscription

Watches what happened to F, not merely that something did.

A listener from subscribe learns the cell changed and reads the new state; an observer is handed the update itself, which is what tells a rename apart from a whole new list. Runs during the drain, before any listener, so state that depends on this one has settled by the time anything draws.

Source

pub fn subscribe<R: Reducer>( &self, callback: impl Fn() + 'static, ) -> Subscription

Source

pub fn binding<R: Reducer>(&self) -> ReducerBinding<R>

A handle to R’s state and actions in this scope, for code that reads or watches them without being a UI hook. See crate::binding.

Source

pub fn snapshot_states(&self) -> HashMap<TypeId, Rc<dyn Any>>

Returns a shallow clone of every reducer state currently held by this scope, keyed by the reducer’s TypeId. Used by the router to cache page state in memory while the page is not mounted.

Source

pub fn restore_states(&self, states: HashMap<TypeId, Rc<dyn Any>>)

Pre-populates reducer cells with previously cached states. This is the inverse of snapshot_states: when a page is remounted, restoring its state before install runs lets the page find ready data instead of defaults.

Source§

impl Scope

Source

pub fn child(&self) -> Scope

A new scope under this one, removed when this one is.

Source

pub fn child_in(&self, outlet: Outlet) -> Scope

A new scope under this one, in outlet.

Source

pub fn remove(&self)

Removes this scope and every scope under it, now: children before their parent, and each one’s resources the last first.

From the moment this is called, every Scope naming them is dead. Removing a scope that is already gone does nothing.

Source

pub fn is_alive(&self) -> bool

Whether this scope is still there.

Source

pub fn parent(&self) -> Option<Scope>

The scope this one sits under, if it has one and it is still there.

Source

pub fn outlet(&self) -> Option<Outlet>

Which of its parent’s outlets this scope sits in.

Source

pub fn ancestors(&self) -> Vec<Scope>

The scopes above this one, the nearest first.

Source

pub fn children_in(&self, outlet: Outlet) -> Vec<Scope>

The scopes right under this one, in outlet, oldest first.

Source

pub fn beside(&self) -> Vec<Scope>

The scopes right under this one in any outlet but MAIN, oldest first: what a layout mounts beside its chain.

Source

pub fn owner_of<R: 'static>(&self) -> Option<Scope>

Where R is read from here: this scope if it claimed R, or the nearest one above that exports it.

The two ends are asked different questions on purpose. A segment may read anything it claimed itself; what a scope above claimed is its own business unless it said otherwise in Exports.

Source

pub fn subtree(&self) -> Vec<Scope>

This scope and every scope under it, children first.

Source

pub fn guard(&self) -> ScopeGuard

Removes this scope when the guard is dropped.

Source

pub fn key(&self) -> usize

Identifies this scope, and never another one.

Trait Implementations§

Source§

impl Clone for Scope

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Scope

Source§

impl Debug for Scope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Scope

Source§

impl Hash for Scope

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Scope

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Scope

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin for Scope

§

impl UnwindSafe for Scope

Blanket Implementations§

Source§

impl<M> AllowedSignal<M> for M
where M: 'static,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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