add a lifetime to the properties trait and make the manual spread example work

This commit is contained in:
Evan Almloff committed 2023-09-20 16:15:11 -05:00
1 parent fc8c25280a
commit fa494349fe
7 files changed
+220 -198

No files matched your search

+5 -5
View File
@@ -32,7 +32,7 @@ use crate::innerlude::*;
/// data: &'a str
/// }
/// ```
pub trait Properties: Sized {
pub trait Properties<'a>: Sized {
/// The type of the builder for this component.
/// Used to create "in-progress" versions of the props.
type Builder;
@@ -41,7 +41,7 @@ pub trait Properties: Sized {
const IS_STATIC: bool;
/// Create a builder for this component.
fn builder(cx: &ScopeState) -> Self::Builder;
fn builder(cx: &'a ScopeState) -> Self::Builder;
/// Memoization can only happen if the props are valid for the 'static lifetime
///
@@ -51,7 +51,7 @@ pub trait Properties: Sized {
unsafe fn memoize(&self, other: &Self) -> bool;
}
impl Properties for () {
impl Properties<'_> for () {
type Builder = EmptyBuilder;
const IS_STATIC: bool = true;
fn builder(_cx: &ScopeState) -> Self::Builder {
@@ -70,8 +70,8 @@ impl EmptyBuilder {
/// This utility function launches the builder method so rsx! and html! macros can use the typed-builder pattern
/// to initialize a component's props.
pub fn fc_to_builder<'a, T: Properties + 'a>(
cx: &ScopeState,
pub fn fc_to_builder<'a, T: Properties<'a> + 'a>(
cx: &'a ScopeState,
_: fn(Scope<'a, T>) -> Element<'a>,
) -> T::Builder {
T::builder(cx)