Spamming lifetimes until it still doesn't work

This commit is contained in:
Daan Vanoverloop 2022-09-10 17:29:58 +02:00
parent a0a3ebb856
commit 6b80f31406
Signed by: Danacus
GPG Key ID: F2272B50E129FC5C
1 changed files with 59 additions and 49 deletions

View File

@ -11,7 +11,7 @@ use sycamore::{builder::prelude::*, component::Prop, prelude::*};
macro_rules! editable {
($type:ty => $editor:ty) => {
impl<'s: 'a, 'a, G: Html> Editable<'s, 'a, G> for $type {
impl<'d, 's, 't, G: Html> Editable<'d, 's, 't, G> for $type {
type Editor = $editor;
}
};
@ -48,8 +48,8 @@ macro_rules! edit_struct {
paste! {
pub struct [<$struct Edit>];
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, $struct> for [<$struct Edit>] {
fn edit(cx: Scope<'a>, props: EditProps<'a, $struct>) -> View<G> {
impl<'d, 's, 't, G: Html> Editor<'d, 's, 't, G, $struct> for [<$struct Edit>] {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, $struct>) -> View<G> {
let state = props.state;
link_fields!(cx, $($prop,)* => state as $struct);
view! { cx,
@ -90,8 +90,8 @@ macro_rules! edit_enum {
paste! {
pub struct [<$enum Edit>];
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, $enum> for [<$enum Edit>] {
fn edit(cx: Scope<'a>, props: EditProps<'a, $enum>) -> View<G> {
impl<'d, 's, 't, G: Html> Editor<'d, 's, 't, G, $enum> for [<$enum Edit>] {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, $enum>) -> View<G> {
let state = props.state;
link_variants!(cx, $selected =>
@ -129,40 +129,40 @@ impl<'a, T> From<&'a Signal<T>> for EditProps<'a, T> {
}
}
pub trait IntoEdit<'s: 'a, 'a, G: Html> {
fn edit(self, cx: BoundedScope<'a, 's>) -> View<G>;
pub trait IntoEdit<'d, 's, G: Html> {
fn edit(self, cx: BoundedScope<'d, 's>) -> View<G>;
}
impl<'s: 'a, 'a, G: Html, T: Editable<'s, 'a, G> + 'a> IntoEdit<'s, 'a, G> for &'a Signal<T>
impl<'d, 's, 't, G: Html, T: Editable<'d, 's, 't, G> + 't> IntoEdit<'d, 's, G> for &'d Signal<T>
where
EditProps<'a, T>: From<&'a Signal<T>>,
EditProps<'d, T>: From<&'d Signal<T>>,
{
fn edit(self, cx: BoundedScope<'a, 's>) -> View<G> {
fn edit(self, cx: BoundedScope<'d, 's>) -> View<G> {
T::edit(cx, self.into())
}
}
pub trait Edit<'s: 'a, 'a, G: Html>: Sized {
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, Self>) -> View<G>;
pub trait Edit<'d, 's, 't, G: Html>: Sized {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, Self>) -> View<G>;
}
impl<'s: 'a, 'a, G, E, Type> Edit<'s, 'a, G> for Type
impl<'d, 's, 't, G, E, Type> Edit<'d, 's, 't, G> for Type
where
G: Html,
E: Editor<'s, 'a, G, Type>,
Type: Editable<'s, 'a, G, Editor = E> + 'a,
E: Editor<'d, 's, 't, G, Type>,
Type: Editable<'d, 's, 't, G, Editor = E> + 't,
{
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, Self>) -> View<G> {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, Self>) -> View<G> {
E::edit(cx, props)
}
}
pub trait Editor<'s: 'a, 'a, G: Html, Type: 'a>: Sized {
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, Type>) -> View<G>;
pub trait Editor<'d, 's, 't, G: Html, Type: 't>: Sized {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, Type>) -> View<G>;
}
pub trait Editable<'s: 'a, 'a, G: Html>: Sized + 'a {
type Editor: Editor<'s, 'a, G, Self>;
pub trait Editable<'d, 's, 't, G: Html>: Sized + 't {
type Editor: Editor<'d, 's, 't, G, Self>;
}
edit_struct!(EventSpec => ("Name", name), ("Description", description), ("Event type", event_type));
@ -179,8 +179,8 @@ edit_struct!(FreeForAllGameSpec => );
pub struct StringEdit;
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, String> for StringEdit {
fn edit(cx: Scope<'a>, props: EditProps<'a, String>) -> View<G> {
impl<'d, 's, 't, G: Html> Editor<'d, 's, 't, G, String> for StringEdit {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, String>) -> View<G> {
view! { cx,
input(bind:value=props.state)
}
@ -191,11 +191,11 @@ editable!(String => StringEdit);
pub struct StubEdit;
impl<'s: 'a, 'a, G: Html, T> Editor<'s, 'a, G, T> for StubEdit
impl<'d, 's, 't, G: Html, T> Editor<'d, 's, 't, G, T> for StubEdit
where
T: Editable<'s, 'a, G, Editor = StubEdit>,
T: Editable<'d, 's, 't, G, Editor = StubEdit>,
{
fn edit(cx: Scope<'a>, _props: EditProps<'a, T>) -> View<G> {
fn edit(cx: BoundedScope<'d, 's>, _props: EditProps<'d, T>) -> View<G> {
view! { cx,
i { "Editor Unimplemented" }
}
@ -204,11 +204,11 @@ where
pub struct InputEdit;
impl<'s: 'a, 'a, G: Html, T> Editor<'s, 'a, G, T> for InputEdit
impl<'d, 's, 't, G: Html, T> Editor<'d, 's, 't, G, T> for InputEdit
where
T: Editable<'s, 'a, G, Editor = InputEdit> + FromStr + ToString + Default,
T: Editable<'d, 's, 't, G, Editor = InputEdit> + FromStr + ToString + Default,
{
fn edit(cx: Scope<'a>, props: EditProps<'a, T>) -> View<G> {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, T>) -> View<G> {
let value = create_signal(cx, props.state.get_untracked().to_string());
create_effect(cx, || {
@ -236,8 +236,8 @@ editable!(f32 => InputEdit);
pub struct BoolEdit;
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, bool> for BoolEdit {
fn edit(cx: Scope<'a>, props: EditProps<'a, bool>) -> View<G> {
impl<'d, 's, 't, G: Html> Editor<'d, 's, 't, G, bool> for BoolEdit {
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, bool>) -> View<G> {
view! { cx,
input(type="checkbox", bind:checked=props.state)
}
@ -248,14 +248,18 @@ editable!(bool => BoolEdit);
pub struct VecEdit;
impl<'s: 'a, 'a, G, T, I> Editor<'s, 'a, G, I> for VecEdit
impl<'d, 's, 't, 'c, G, T, I> Editor<'d, 's, 't, G, I> for VecEdit
where
't: 'c,
's: 'd,
'd: 's,
't: 'd,
G: Html,
T: Editable<'s, 'a, G> + Clone + PartialEq + 'a,
I: IntoIterator<Item = T> + FromIterator<T> + Clone + 'a,
T: Editable<'c, 's, 't, G> + Clone + PartialEq + 't,
I: IntoIterator<Item = T> + FromIterator<T> + Clone + 't,
{
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, I>) -> View<G> {
let vec: &'a Signal<Vec<&'a Signal<T>>> = create_signal(
fn edit(cx: BoundedScope<'d, 's>, props: EditProps<'d, I>) -> View<G> {
let vec: &'s Signal<Vec<&'s Signal<T>>> = create_signal(
cx,
props
.state
@ -284,9 +288,10 @@ where
cx,
IndexedProps::builder()
.iterable(vec)
.view(|cx: BoundedScope<'_, '_>, x: &'a Signal<T>| {
.view(|cx: BoundedScope<'s, 's>, x: &'s Signal<T>| {
//view! { cx, (T::edit(cx, EditProps { state: x })) }
T::edit(cx, EditProps { state: x })
//T::edit(cx, EditProps { state: x })
view! { cx, }
})
.build(),
);
@ -317,16 +322,18 @@ where
}
}
/*
#[component]
pub fn VecTest<
'a,
's,
'c,
'd,
't,
G: Html,
T: 'a + PartialEq + Clone + Editable<'a, G, Editor = E>,
E: Editor<'a, G, T>,
T: 't + PartialEq + Clone + Editable<'s, 'd, 't, G, Editor = E>,
E: Editor<'s, 'd, 't, G, T>,
>(
cx: Scope<'a>,
props: EditProps<'a, Vec<T>>,
cx: BoundedScope<'d, 's>,
props: EditProps<'d, Vec<T>>,
) -> View<G> {
/*
let signals: &'a Signal<Vec<&'a Signal<String>>> = create_signal(
@ -352,9 +359,9 @@ pub fn VecTest<
view! { cx,
Indexed(
iterable=signals,
view=|cx: BoundedScope<'_, 'a>, signal: &'a Signal<T>| {
view=|cx: BoundedScope<'_, 'd>, signal: &'d Signal<T>| {
view! { cx,
//(something_with_signal(cx, SignalWrapper(signal)))
(something_with_signal(cx, EditProps { state: signal }))
//(E::edit(cx, EditProps { state: signal }))
//(T::edit(cx, EditProps { state: signal }))
//(signal.edit(cx))
@ -363,12 +370,11 @@ pub fn VecTest<
)
}
}
*/
pub struct SignalWrapper<'a, T>(&'a Signal<T>);
#[component]
pub fn something_with_signal<'a, G: Html, T: 'a>(
pub fn something_with_signal<'a, 'b, 'c, G: Html, T: 'a + Editable<'b, 'c, 'a, G>>(
cx: Scope<'a>,
signal: EditProps<'a, T>,
) -> View<G> {
@ -376,10 +382,14 @@ pub fn something_with_signal<'a, G: Html, T: 'a>(
view! { cx, "Something" }
}
impl<'s: 'a, 'a, G, T> Editable<'s, 'a, G> for Vec<T>
impl<'d, 's, 't, 'c, G, T> Editable<'d, 's, 't, G> for Vec<T>
where
't: 'c,
's: 'd,
'd: 's,
't: 'd,
G: Html,
T: Editable<'s, 'a, G> + Clone + PartialEq + 'a,
T: Editable<'c, 's, 't, G> + Clone + PartialEq + 't,
{
type Editor = VecEdit;
}