Skip to main content

ReadGlobal

Trait ReadGlobal 

Source
pub trait ReadGlobal {
    // Required method
    fn global(cx: &App) -> &Self;
}
Expand description

Reads the global of the implementing type from an App, as in Theme::global(cx).

Every Global type implements this trait. Use it to name a global by type instead of calling App::global with a turbofish.

§Examples

struct Theme {
    dark: bool,
}

impl Global for Theme {}

app.set_global(Theme { dark: true });
assert!(app.read(|cx| Theme::global(cx).dark));

Required Methods§

Source

fn global(cx: &App) -> &Self

Returns the global of this type.

§Panics

Panics if no global of this type has been set.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Global> ReadGlobal for T