Context

Trait Context 

Source
pub trait Context: Default {
    type Scope;

    // Required methods
    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.

Required Associated Types§

Source

type Scope

Identifies a layer of scope.

Required Methods§

Source

fn nth_last_scope(&self, n: usize) -> Option<TypeId>

Gets the nth topmost scope type ID.

Source

fn get<T>(&self, scope: TypeId) -> Option<&T>
where T: 'static,

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

Source

fn get_each<T>(&self) -> Box<dyn Iterator<Item = &T> + '_>
where T: 'static,

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

Source

fn get_mut<T, F>(&mut self, scope: TypeId, default: F) -> &mut T
where F: FnOnce() -> T, T: 'static,

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

Source

fn start_scope<T: 'static>(&mut self) -> Self::Scope

Pushes the type to the scope stack.

This method is automatically called from Xylem::convert.

Source

fn end_scope(&mut self, scope: Self::Scope)

Pops a type from the scope stack.

This method is automatically called from Xylem::convert.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§