FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    ferroui_static_view_locator

    module · ferroui-static-view-locator · v0.5.0

    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, MissingViewTable), the run-time type of a view model (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

    [dependencies]
    ferroui-static-view-locator = "0.4"
    
    [build-dependencies]
    ferroui-static-view-locator-build = "0.4"
    
    // build.rs
    fn main() {
        ferroui_static_view_locator_build::StaticViewLocatorBuild::from_env().run();
    }
    
    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

    Contents

    Availability

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