FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    DefaultViewLocator

    struct · ferroui-reactiveui · v0.5.0

    struct DefaultViewLocator
    

    The view locator of ReactiveUI.Binding (DefaultViewLocator). It resolves the view of a view model in three tiers:

    1. the generated lookups (set_generated_view_dispatch), the latest registered first;
    2. the mappings of the locator (map, map_factory, ViewMappingBuilder), by the type of the view model and the contract;
    3. the service locator, for a view registered as dyn IViewForOf<VM>.

    A view model held as Rc<dyn Any> goes through the first two tiers (IViewLocator::resolve_view); IViewLocator::resolve_view_unsafe adds the third for the view model types the locator knows by their TypeId.

    Not ported: the lookup of a view by the name of the type of its view model, which needs reflection.

    Deviation (DEVIATIONS.md, ReactiveUI): closing IViewFor<> over the run-time type of a view model (MakeGenericType) needs reflection. IViewLocator::resolve_view_unsafe asks the service locator for the view model types recorded at run time instead: those of the mappings, of register_view_for, of a typed resolution, and of register_view_model_type. The mappings are kept in a RefCell, as everything is single-threaded (docs/porting/reactive.md, section 5.1).

    View source

    Members

    new

    fn new() -> Self
    

    A locator with no mapping.

    Source

    set_generated_view_dispatch

    fn set_generated_view_dispatch(dispatch: GeneratedViewDispatch)
    

    Adds a generated lookup (SetGeneratedViewDispatch). Every lookup is asked, the most recently registered first, and the first view one gives wins; adding a lookup already registered (the same Rc) does nothing.

    Source

    register_view_model_type

    fn register_view_model_type<VM: 'static>()
    

    Records the view model type VM, so that resolve_view_unsafe asks the service locator for dyn IViewForOf<VM> when a view model of that type is held as dyn Any.

    Not an upstream member: it stands for the run-time construction of IViewFor<TViewModel>.

    Source

    map

    fn map<VM: 'static, V: IViewFor + Default>(self: &Self, contract: Option<&str>)
    

    Maps the view model type VM, under contract (None for the default), to a new view of type V, replacing an existing mapping (Map<TViewModel, TView>(string?)).

    Source

    map_factory

    fn map_factory<VM: 'static>(self: &Self, factory: impl Fn() -> Rc<dyn IViewFor> + 'static, contract: Option<&str>)
    

    Maps the view model type VM, under contract, to the view factory creates, replacing an existing mapping (Map<TViewModel>(Func<IViewFor>, string?)).

    Source

    unmap

    fn unmap<VM: 'static>(self: &Self, contract: Option<&str>) -> bool
    

    Removes the mapping of the view model type VM under contract; whether there was one (Unmap<TViewModel>(string?)).

    Source

    resolve_view_of

    fn resolve_view_of<VM: 'static>(self: &Self, view_model: &Rc<VM>, contract: Option<&str>) -> Option<Rc<dyn IViewFor>>
    

    Resolves the view of view_model through its compile-time type VM, in the three tiers, and sets the view's view model (ResolveView<TViewModel>(TViewModel, string?)).

    Source

    resolve_view_for

    fn resolve_view_for<VM: 'static>(self: &Self, contract: Option<&str>) -> Option<Rc<dyn IViewForOf<VM>>>
    

    Resolves a view of the type VM without a view model, from the mappings, then the service locator; a mapped view that is not an IViewForOf<VM> is skipped, and the view's view model is left unset (ResolveView<TViewModel>(string?)).

    Source

    create_mapping_builder

    fn create_mapping_builder(self: &Self) -> ViewMappingBuilder<'_>
    

    A ViewMappingBuilder that registers its mappings on this locator (CreateMappingBuilder).

    Source

    Trait implementations

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.