# DefaultViewLocator

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/binding/view/struct-defaultviewlocator/

**struct** · [`ferroui-reactiveui`](/docs/0.5.0/api/ferroui-reactiveui/) · v0.5.0

```rust
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`](/docs/0.5.0/api/ferroui-reactiveui/binding/view/struct-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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L67)

## Members

- [`new`](#function-new)
- [`set_generated_view_dispatch`](#function-set_generated_view_dispatch)
- [`register_view_model_type`](#function-register_view_model_type)
- [`map`](#function-map)
- [`map_factory`](#function-map_factory)
- [`unmap`](#function-unmap)
- [`resolve_view_of`](#function-resolve_view_of)
- [`resolve_view_for`](#function-resolve_view_for)
- [`create_mapping_builder`](#function-create_mapping_builder)

<a id="function-new"></a>

### new

```rust
fn new() -> Self
```

A locator with no mapping.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L88)

<a id="function-set_generated_view_dispatch"></a>

### set_generated_view_dispatch

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L95)

<a id="function-register_view_model_type"></a>

### register_view_model_type

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L119)

<a id="function-map"></a>

### map

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L125)

<a id="function-map_factory"></a>

### map_factory

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L131)

<a id="function-unmap"></a>

### unmap

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L139)

<a id="function-resolve_view_of"></a>

### resolve_view_of

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L146)

<a id="function-resolve_view_for"></a>

### resolve_view_for

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L153)

<a id="function-create_mapping_builder"></a>

### create_mapping_builder

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/default_view_locator.rs#L176)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ViewLocatorMixins`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/trait-viewlocatormixins/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `Default`
- `Debug`
- [`IEnableLogger`](/docs/0.5.0/api/ferroui-splat/logging/trait-ienablelogger/)
- [`IViewLocator`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/trait-iviewlocator/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
