# ferroui_static_view_locator

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-static-view-locator/

**module** · [`ferroui-static-view-locator`](/docs/0.5.0/api/ferroui-static-view-locator/) · v0.5.0

```rust
module ferroui_static_view_locator
```

ferroui-static-view-locator

View locators generated at build time: a locator maps the type of a view model to the view
that shows it, through a table written by the build script of the crate, with no lookup of a
type by its name and no scan of the types of the program at run time. A port of
StaticViewLocator (<https://github.com/wieslawsoltes/StaticViewLocator>), a C# source
generator; the plan and the deviations are in `docs/porting/static-view-locator.md`.

Three crates make the port:

- this crate: the attributes, the tables a generated locator holds ([`ViewTable`](/docs/0.5.0/api/ferroui-static-view-locator/type_alias-viewtable/),
  [`MissingViewTable`](/docs/0.5.0/api/ferroui-static-view-locator/type_alias-missingviewtable/)), the run-time type of a view model ([`RuntimeType`](/docs/0.5.0/api/ferroui-static-view-locator/struct-runtimetype/)) and what the
  generated adapters call;
- `ferroui-static-view-locator-macros`: `static_view_locator` and `static_view_mapping`,
  re-exported here;
- `ferroui-static-view-locator-build`: the generator, which the build script of the crate
  runs (the counterpart of the incremental generator of the reference).
## Usage

```toml
[dependencies]
ferroui-static-view-locator = "0.4"

[build-dependencies]
ferroui-static-view-locator-build = "0.4"
```

```ignore
// build.rs
fn main() {
    ferroui_static_view_locator_build::StaticViewLocatorBuild::from_env().run();
}
```

```ignore
use ferroui_static_view_locator::{static_view_locator, static_view_mapping};

#[static_view_locator(generate_data_template = true, data_template_match_types = [ViewModelBase])]
#[static_view_mapping(LoginViewModel, LogInView)]
#[derive(Default)]
pub struct ViewLocator;
```

The attribute writes the struct and includes the file the build script generated for it:
the tables and the members the options ask for, in an `impl` block of the struct (the
`partial class` of the reference). By convention `crate::view_models::SettingsViewModel` is
shown by `crate::views::SettingsView`, and `crate::settings_view_model::SettingsViewModel` by
`crate::settings_view::SettingsView`; a view is a class of the object model that derives from
`UserControl` or `Window` and has a constructor without parameters (`new()`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/StaticViewLocator/FerroUI.StaticViewLocator/lib.rs#L1)

## Contents

- [`static_view_locator`](/docs/0.5.0/api/ferroui-static-view-locator/use-static_view_locator/) — use
- [`static_view_mapping`](/docs/0.5.0/api/ferroui-static-view-locator/use-static_view_mapping/) — use
- [`RuntimeType`](/docs/0.5.0/api/ferroui-static-view-locator/struct-runtimetype/) — struct
- [`NameTable`](/docs/0.5.0/api/ferroui-static-view-locator/struct-nametable/) — struct
- [`TypeEntry`](/docs/0.5.0/api/ferroui-static-view-locator/struct-typeentry/) — struct
- [`TypeTable`](/docs/0.5.0/api/ferroui-static-view-locator/struct-typetable/) — struct
- [`ViewResolutionMode`](/docs/0.5.0/api/ferroui-static-view-locator/enum-viewresolutionmode/) — enum
- [`ViewFactory`](/docs/0.5.0/api/ferroui-static-view-locator/type_alias-viewfactory/) — type alias
- [`ViewTable`](/docs/0.5.0/api/ferroui-static-view-locator/type_alias-viewtable/) — type alias
- [`MissingViewTable`](/docs/0.5.0/api/ferroui-static-view-locator/type_alias-missingviewtable/) — type alias
- [`TypeSet`](/docs/0.5.0/api/ferroui-static-view-locator/type_alias-typeset/) — type alias
- [`upcast`](/docs/0.5.0/api/ferroui-static-view-locator/function-upcast/) — function
- [`text_view`](/docs/0.5.0/api/ferroui-static-view-locator/function-text_view/) — function
- [`set_data_context`](/docs/0.5.0/api/ferroui-static-view-locator/function-set_data_context/) — function
- [`view_not_found_text`](/docs/0.5.0/api/ferroui-static-view-locator/function-view_not_found_text/) — function
- [`unable_to_create_view`](/docs/0.5.0/api/ferroui-static-view-locator/function-unable_to_create_view/) — function

## Availability

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