Struct druid::env::Key

source ·
pub struct Key<T> { /* private fields */ }
Expand description

A typed Env key.

This lets you retrieve values of a given type. The parameter implements ValueType. For “expensive” types, this is a reference, so the type for a string is Key<&str>.

Examples

const IMPORTANT_LABEL_COLOR: Key<Color> = Key::new("org.linebender.example.important-label-color");

fn important_label() -> Label<()> {
    Label::new("Warning!").with_text_color(IMPORTANT_LABEL_COLOR)
}

fn main() {
    let main_window = WindowDesc::new(important_label());

    AppLauncher::with_window(main_window)
        .configure_env(|env, _state| {
            // The `Key` must be set before it is used.
            env.set(IMPORTANT_LABEL_COLOR, Color::rgb(1.0, 0.0, 0.0));
        });
}

Implementations§

Create a new strongly typed Key with the given string value. The type of the key will be inferred.

Examples
use druid::Key;
use druid::piet::Color;

let float_key: Key<f64> = Key::new("org.linebender.example.a.very.good.float");
let color_key: Key<Color> = Key::new("org.linebender.example.a.very.nice.color");

Create an untyped Key with the given string value.

WARNING: This is not for general usage - it’s only useful for inspecting the contents of an Env - this is expected to be used for debugging, loading, and manipulating themes.

Return this key’s raw string value.

This should only be needed for things like debugging or for building other tooling that needs to inspect keys.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Determine whether two values are the same. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Returns true if this item has changed between the old and new Env.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Performs the conversion.
Performs the conversion.
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more