Struct patternfly_yew::ContextWrapper
source · Implementations§
source§impl<C> ContextWrapper<C>where
C: Clone + PartialEq + 'static,
impl<C> ContextWrapper<C>where
C: Clone + PartialEq + 'static,
sourcepub fn new(context: Option<(C, ContextHandle<C>)>) -> Self
pub fn new(context: Option<(C, ContextHandle<C>)>) -> Self
Examples found in repository?
src/utils/context.rs (line 33)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
pub fn with<COMP, F>(ctx: &Context<COMP>, cb: F) -> Self
where
COMP: BaseComponent,
F: Fn(C) -> COMP::Message + 'static,
{
let cb = ctx.link().callback(cb);
Self::new(ctx.link().context(cb))
}
pub fn set(&mut self, context: C) -> bool {
let context = Some(context);
if self.context != context {
self.context = context;
true
} else {
false
}
}
}
impl<C, COMP, F> From<(&Context<COMP>, F)> for ContextWrapper<C>
where
COMP: Component,
F: Fn(C) -> COMP::Message + 'static,
C: PartialEq + Clone,
{
fn from((ctx, f): (&Context<COMP>, F)) -> Self {
let link = ctx.link().clone();
Self::new(link.clone().context(Callback::from(move |v| {
link.send_message(f(v));
})))
}pub fn with<COMP, F>(ctx: &Context<COMP>, cb: F) -> Selfwhere
COMP: BaseComponent,
F: Fn(C) -> COMP::Message + 'static,
sourcepub fn set(&mut self, context: C) -> bool
pub fn set(&mut self, context: C) -> bool
Examples found in repository?
src/modal.rs (line 82)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::Close => {
if let Some(onclose) = &ctx.props().onclose {
onclose.emit(());
} else if let Some(backdrop) = self.backdrop.deref() {
backdrop.close();
}
}
Msg::SetBackdrop(backdrop) => {
self.backdrop.set(backdrop);
}
}
true
}More examples
src/about.rs (line 54)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::Close => {
if let Some(onclose) = &ctx.props().onclose {
onclose.emit(());
} else {
if let Some(backdrop) = self.backdrop.deref() {
backdrop.close();
}
}
}
Msg::SetBackdrop(backdropper) => {
self.backdrop.set(backdropper);
}
}
true
}Methods from Deref<Target = Option<C>>§
1.0.0 · sourcepub fn as_ref(&self) -> Option<&T>
pub fn as_ref(&self) -> Option<&T>
Converts from &Option<T> to Option<&T>.
Examples
Converts an Option<String> into an Option<usize>, preserving
the original. The map method takes the self argument by value, consuming the original,
so this technique uses as_ref to first take an Option to a reference
to the value inside the original.
let text: Option<String> = Some("Hello, world!".to_string());
// First, cast `Option<String>` to `Option<&String>` with `as_ref`,
// then consume *that* with `map`, leaving `text` on the stack.
let text_length: Option<usize> = text.as_ref().map(|s| s.len());
println!("still can print text: {text:?}");1.40.0 · sourcepub fn as_deref(&self) -> Option<&<T as Deref>::Target>where
T: Deref,
pub fn as_deref(&self) -> Option<&<T as Deref>::Target>where
T: Deref,
Converts from Option<T> (or &Option<T>) to Option<&T::Target>.
Leaves the original Option in-place, creating a new one with a reference
to the original one, additionally coercing the contents via Deref.
Examples
let x: Option<String> = Some("hey".to_owned());
assert_eq!(x.as_deref(), Some("hey"));
let x: Option<String> = None;
assert_eq!(x.as_deref(), None);1.0.0 · sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns an iterator over the possibly contained value.
Examples
let x = Some(4);
assert_eq!(x.iter().next(), Some(&4));
let x: Option<u32> = None;
assert_eq!(x.iter().next(), None);sourcepub fn contains<U>(&self, x: &U) -> boolwhere
U: PartialEq<T>,
🔬This is a nightly-only experimental API. (option_result_contains)
pub fn contains<U>(&self, x: &U) -> boolwhere
U: PartialEq<T>,
option_result_contains)Returns true if the option is a Some value containing the given value.
Examples
#![feature(option_result_contains)]
let x: Option<u32> = Some(2);
assert_eq!(x.contains(&2), true);
let x: Option<u32> = Some(3);
assert_eq!(x.contains(&2), false);
let x: Option<u32> = None;
assert_eq!(x.contains(&2), false);Trait Implementations§
Auto Trait Implementations§
impl<C> !RefUnwindSafe for ContextWrapper<C>
impl<C> !Send for ContextWrapper<C>
impl<C> !Sync for ContextWrapper<C>
impl<C> Unpin for ContextWrapper<C>where
C: Unpin,
impl<C> !UnwindSafe for ContextWrapper<C>
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>
source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.