Trait xylem::Context[][src]

pub trait Context: Default {
    type Scope;
    fn nth_last_scope(&self, n: usize) -> Option<TypeId>;
fn get<T>(&self, scope: TypeId) -> Option<&T>
    where
        T: 'static
;
fn get_each<T>(&self) -> Box<dyn Iterator<Item = &T>>
    where
        T: 'static
;
fn get_mut<T, F>(&mut self, scope: TypeId, default: F) -> &mut T
    where
        F: FnOnce() -> T,
        T: 'static
;
fn start_scope<T: 'static>(&mut self) -> Self::Scope;
fn end_scope(&mut self, scope: Self::Scope); }
Expand description

The context of a conversion.

The context provides a stack of scopes. A scope is typically the duration of the conversion of a value, and the stack grows when types are converted recursively. The top of the stack is the current scope.

Each layer of the stack has its own typemap, which provides access to an arbitrary object bound accessible during the scope.

It is strongly discouraged to have recursive types resulting in multiple layers of the scope to have the same type ID, which may need to strange behavior when accessing the typemap, becaues only the newest layer of the type is accessible.

Associated Types

Identifies a layer of scope.

Required methods

Gets the nth topmost scope type ID.

Gets a shared reference to the storage of type T in the newest layer of the scope.

Gets a shared reference to the storage of type T in each layer, from top to bottom, if exists.

Gets a mutable reference to the storage of type T in the newest layer of the scope.

Pushes the type to the scope stack.

This method is automatically called from Xylem::convert.

Pops a type from the scope stack.

This method is automatically called from Xylem::convert.

Implementors