pub struct PropertyInputTypes<Tuple>(/* private fields */);Expand description
Represents the strong types of each input of a property.
§Examples
The example uses property_input_types! to collect the types and compares it to a manually generated types. Note
that the type is a tuple even if there is only one input.
#[property(CONTEXT)]
pub fn foo(child: impl IntoUiNode, bar: impl IntoVar<bool>) -> UiNode {
}
assert_eq!(
property_input_types!(foo).type_id(),
PropertyInputTypes::<(Var<bool>,)>::unit().type_id(),
);You can use the collected types in advanced code generation, such as attribute proc-macros targeting property assigns in widgets.
The next example demonstrates a trait that uses auto-deref to convert a trait bound to a bool:
#[property(CONTEXT)]
pub fn foo(child: impl IntoUiNode, bar: impl IntoVar<bool>) -> UiNode {
}
trait SingleBoolVar {
fn is_single_bool_var(self) -> bool;
}
// match
impl<'a> SingleBoolVar for &'a PropertyInputTypes<(Var<bool>,)> {
fn is_single_bool_var(self) -> bool {
true
}
}
// fallback impl
impl<T: Send + 'static> SingleBoolVar for PropertyInputTypes<T> {
fn is_single_bool_var(self) -> bool {
false
}
}
assert!((&property_input_types!(foo)).is_single_bool_var());Learn more about how this trick works and limitations here.
Implementations§
Source§impl<Tuple> PropertyInputTypes<Tuple>
impl<Tuple> PropertyInputTypes<Tuple>
Trait Implementations§
Source§impl<Tuple> Clone for PropertyInputTypes<Tuple>
impl<Tuple> Clone for PropertyInputTypes<Tuple>
impl<Tuple> Copy for PropertyInputTypes<Tuple>
impl<Tuple> Send for PropertyInputTypes<Tuple>
impl<Tuple> Sync for PropertyInputTypes<Tuple>
Auto Trait Implementations§
impl<Tuple> Freeze for PropertyInputTypes<Tuple>
impl<Tuple> RefUnwindSafe for PropertyInputTypes<Tuple>where
Tuple: RefUnwindSafe,
impl<Tuple> Unpin for PropertyInputTypes<Tuple>where
Tuple: Unpin,
impl<Tuple> UnwindSafe for PropertyInputTypes<Tuple>where
Tuple: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more