FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    FerroLocator

    struct · ferroui-base · v0.5.0

    struct FerroLocator
    

    A scoped service registry.

    Services are keyed by the TypeId of the service type, which can be a concrete type (Foo, fetched as Rc<Foo>) or a trait object type (dyn IFoo, fetched as Rc<dyn IFoo>):

    FerroLocator::current_mutable().bind::<dyn IFoo>().to_constant(Rc::new(Foo::new()));
    let foo: Option<Rc<dyn IFoo>> = FerroLocator::current().get_service::<dyn IFoo>();
    

    Like the rest of the object model the locator is per-thread: the current locator and its registrations are only visible on the thread that made them.

    View source

    Members

    current

    fn current() -> Rc<dyn IFerroDependencyResolver>
    

    The resolver services are looked up in.

    Source

    set_current

    fn set_current(value: Rc<dyn IFerroDependencyResolver>)
    

    Source

    current_mutable

    fn current_mutable() -> Rc<FerroLocator>
    

    The locator services are registered in.

    Source

    set_current_mutable

    fn set_current_mutable(value: Rc<FerroLocator>)
    

    Source

    new

    fn new() -> Self
    

    Source

    with_parent_scope

    fn with_parent_scope(parent_scope: Rc<dyn IFerroDependencyResolver>) -> Self
    

    Creates a locator that falls back to parent_scope for services it has no registration for.

    Source

    bind

    fn bind<T: ?Sized + 'static>(self: &Self) -> RegistrationHelper<'_, T>
    

    Starts the registration of the service type T, which may be a trait object type.

    Source

    bind_to_self

    fn bind_to_self<T: 'static>(self: &Self, constant: Rc<T>) -> &FerroLocator
    

    Registers constant as the service of its own type.

    Source

    bind_to_self_singleton

    fn bind_to_self_singleton<T: Default + 'static>(self: &Self) -> &FerroLocator
    

    Registers a lazily created instance of T as the service of its own type.

    Source

    enter_scope

    fn enter_scope() -> Rc<dyn IDisposable>
    

    Makes a new locator, whose parent is the current resolver, the current one. Disposing the returned value, or dropping its last handle, restores the previous resolver and locator (once).

    Source

    Trait implementations

    Availability

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