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§
source§impl<T> Key<T>
impl<T> Key<T>
sourcepub const fn new(key: &'static str) -> Self
pub const fn new(key: &'static str) -> Self
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");
Trait Implementations§
source§impl<T: ValueType> From<Key<T>> for KeyOrValue<T>
impl<T: ValueType> From<Key<T>> for KeyOrValue<T>
source§fn from(key: Key<T>) -> KeyOrValue<T>
fn from(key: Key<T>) -> KeyOrValue<T>
Converts to this type from the input type.
source§impl<T: PartialEq> PartialEq<Key<T>> for Key<T>
impl<T: PartialEq> PartialEq<Key<T>> for Key<T>
impl<T: Eq> Eq for Key<T>
impl<T> StructuralEq for Key<T>
impl<T> StructuralPartialEq for Key<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Key<T>where
T: RefUnwindSafe,
impl<T> Send for Key<T>where
T: Send,
impl<T> Sync for Key<T>where
T: Sync,
impl<T> Unpin for Key<T>where
T: Unpin,
impl<T> UnwindSafe for Key<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> RoundFrom<T> for T
impl<T> RoundFrom<T> for T
§fn round_from(x: T) -> T
fn round_from(x: T) -> T
Performs the conversion.
§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.