remove TryCatch/fallible rendering in favor of better ErrorBoundary model

This commit is contained in:
Greg Johnston 2024-04-19 20:36:58 -04:00
parent 0c9167fd30
commit 13da1e743d
29 changed files with 13 additions and 917 deletions

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[profile.release] [profile.release]
opt-level = 'z'
codegen-units = 1 codegen-units = 1
lto = true lto = true

View file

@ -297,7 +297,6 @@ where
Chil: Render<LeptosGtk>, Chil: Render<LeptosGtk>,
{ {
type State = LGtkWidgetState<Widg, Props, Chil>; type State = LGtkWidgetState<Widg, Props, Chil>;
type FallibleState = ();
fn build(self) -> Self::State { fn build(self) -> Self::State {
let widget = Object::new::<Widg::Widget>(); let widget = Object::new::<Widg::Widget>();
@ -318,17 +317,6 @@ where
.rebuild(&state.widget, &mut state.properties); .rebuild(&state.widget, &mut state.properties);
self.children.rebuild(&mut state.children); self.children.rebuild(&mut state.children);
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<Widg, Props, Chil> Mountable<LeptosGtk> impl<Widg, Props, Chil> Mountable<LeptosGtk>

View file

@ -150,7 +150,6 @@ where
Rndr: Renderer, Rndr: Renderer,
{ {
type State = ErrorBoundaryViewState<Chil, Fal, Rndr>; type State = ErrorBoundaryViewState<Chil, Fal, Rndr>;
type FallibleState = ();
fn build(self) -> Self::State { fn build(self) -> Self::State {
let placeholder = Rndr::create_placeholder(); let placeholder = Rndr::create_placeholder();
@ -192,17 +191,6 @@ where
} }
state.showing_fallback = !self.errors_empty; state.showing_fallback = !self.errors_empty;
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<Chil, Fal, Rndr> RenderHtml<Rndr> for ErrorBoundaryView<Chil, Fal, Rndr> impl<Chil, Fal, Rndr> RenderHtml<Rndr> for ErrorBoundaryView<Chil, Fal, Rndr>

View file

@ -39,7 +39,6 @@ where
impl<T: IntoView> Render<Dom> for View<T> { impl<T: IntoView> Render<Dom> for View<T> {
type State = T::State; type State = T::State;
type FallibleState = T::FallibleState;
fn build(self) -> Self::State { fn build(self) -> Self::State {
self.0.build() self.0.build()
@ -48,17 +47,6 @@ impl<T: IntoView> Render<Dom> for View<T> {
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
self.0.rebuild(state) self.0.rebuild(state)
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
self.0.try_build()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.0.try_rebuild(state)
}
} }
impl<T: IntoView> RenderHtml<Dom> for View<T> { impl<T: IntoView> RenderHtml<Dom> for View<T> {

View file

@ -73,7 +73,6 @@ where
{ {
type State = type State =
RenderEffectState<EitherKeepAliveState<Chil::State, Fal::State, Rndr>>; RenderEffectState<EitherKeepAliveState<Chil::State, Fal::State, Rndr>>;
type FallibleState = ();
fn build(self) -> Self::State { fn build(self) -> Self::State {
let mut children = Some(self.children); let mut children = Some(self.children);
@ -99,17 +98,6 @@ where
} }
fn rebuild(self, _state: &mut Self::State) {} fn rebuild(self, _state: &mut Self::State) {}
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<const TRANSITION: bool, Fal, Chil, Rndr> RenderHtml<Rndr> impl<const TRANSITION: bool, Fal, Chil, Rndr> RenderHtml<Rndr>
@ -306,7 +294,6 @@ where
Rndr: Renderer + 'static, Rndr: Renderer + 'static,
{ {
type State = SuspendState<Fut::Output, Rndr>; type State = SuspendState<Fut::Output, Rndr>;
type FallibleState = Self::State;
// TODO cancelation if it fires multiple times // TODO cancelation if it fires multiple times
fn build(self) -> Self::State { fn build(self) -> Self::State {
@ -353,17 +340,6 @@ where
} }
}); });
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<Fut, Rndr> RenderHtml<Rndr> for Suspend<Fut> impl<Fut, Rndr> RenderHtml<Rndr> for Suspend<Fut>

View file

@ -96,7 +96,6 @@ struct BodyViewState {
impl Render<Dom> for BodyView { impl Render<Dom> for BodyView {
type State = BodyViewState; type State = BodyViewState;
type FallibleState = BodyViewState;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let el = document().body().expect("there to be a <body> element"); let el = document().body().expect("there to be a <body> element");
@ -113,15 +112,6 @@ impl Render<Dom> for BodyView {
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
// TODO rebuilding dynamic things like this // TODO rebuilding dynamic things like this
} }
fn try_build(self) -> Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(self, state: &mut Self::FallibleState) -> Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl RenderHtml<Dom> for BodyView { impl RenderHtml<Dom> for BodyView {

View file

@ -107,7 +107,6 @@ struct HtmlViewState {
impl Render<Dom> for HtmlView { impl Render<Dom> for HtmlView {
type State = HtmlViewState; type State = HtmlViewState;
type FallibleState = HtmlViewState;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let el = document() let el = document()
@ -126,15 +125,6 @@ impl Render<Dom> for HtmlView {
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
// TODO rebuilding dynamic things like this // TODO rebuilding dynamic things like this
} }
fn try_build(self) -> Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(self, state: &mut Self::FallibleState) -> Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl RenderHtml<Dom> for HtmlView { impl RenderHtml<Dom> for HtmlView {

View file

@ -324,7 +324,6 @@ where
Ch: Render<Dom>, Ch: Render<Dom>,
{ {
type State = RegisteredMetaTagState<E, At, Ch>; type State = RegisteredMetaTagState<E, At, Ch>;
type FallibleState = RegisteredMetaTagState<E, At, Ch>;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let state = self.el.unwrap().build(); let state = self.el.unwrap().build();
@ -334,18 +333,6 @@ where
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
self.el.unwrap().rebuild(&mut state.state); self.el.unwrap().rebuild(&mut state.state);
} }
fn try_build(self) -> leptos::error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> leptos::error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<E, At, Ch> RenderHtml<Dom> for RegisteredMetaTag<E, At, Ch> impl<E, At, Ch> RenderHtml<Dom> for RegisteredMetaTag<E, At, Ch>
@ -441,22 +428,10 @@ struct MetaTagsView {
// client-side rendering is handled by the individual components // client-side rendering is handled by the individual components
impl Render<Dom> for MetaTagsView { impl Render<Dom> for MetaTagsView {
type State = (); type State = ();
type FallibleState = ();
fn build(self) -> Self::State {} fn build(self) -> Self::State {}
fn rebuild(self, state: &mut Self::State) {} fn rebuild(self, state: &mut Self::State) {}
fn try_build(self) -> leptos::error::Result<Self::FallibleState> {
Ok(())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> leptos::error::Result<()> {
Ok(())
}
} }
impl RenderHtml<Dom> for MetaTagsView { impl RenderHtml<Dom> for MetaTagsView {

View file

@ -193,7 +193,6 @@ struct TitleViewState {
impl Render<Dom> for TitleView { impl Render<Dom> for TitleView {
type State = TitleViewState; type State = TitleViewState;
type FallibleState = TitleViewState;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let el = self.el(); let el = self.el();
@ -221,15 +220,6 @@ impl Render<Dom> for TitleView {
fn rebuild(self, _state: &mut Self::State) { fn rebuild(self, _state: &mut Self::State) {
// TODO should this rebuild? // TODO should this rebuild?
} }
fn try_build(self) -> Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(self, state: &mut Self::FallibleState) -> Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl RenderHtml<Dom> for TitleView { impl RenderHtml<Dom> for TitleView {

View file

@ -122,7 +122,7 @@ where
Rndr, Rndr,
>, >,
>; >;
type FallibleState = (); // TODO // TODO
fn build(self) -> Self::State { fn build(self) -> Self::State {
let location = Loc::new().unwrap(); // TODO let location = Loc::new().unwrap(); // TODO
@ -178,17 +178,6 @@ where
} }
fn rebuild(self, state: &mut Self::State) {} fn rebuild(self, state: &mut Self::State) {}
fn try_build(self) -> leptos::error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> leptos::error::Result<()> {
todo!()
}
} }
impl<Rndr, Loc, FallbackFn, Fallback, Children> RenderHtml<Rndr> impl<Rndr, Loc, FallbackFn, Fallback, Children> RenderHtml<Rndr>
@ -640,7 +629,6 @@ where
R: Renderer + 'static, R: Renderer + 'static,
{ {
type State = Outlet<R>; type State = Outlet<R>;
type FallibleState = ();
fn build(self) -> Self::State { fn build(self) -> Self::State {
self self
@ -649,17 +637,6 @@ where
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
todo!() todo!()
} }
fn try_build(self) -> leptos::error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> leptos::error::Result<()> {
todo!()
}
} }
impl<R> RenderHtml<R> for Outlet<R> impl<R> RenderHtml<R> for Outlet<R>
@ -895,7 +872,6 @@ where
R: Renderer + 'static, R: Renderer + 'static,
{ {
type State = NestedRouteState<Matcher, R>; type State = NestedRouteState<Matcher, R>;
type FallibleState = ();
fn build(self) -> Self::State { fn build(self) -> Self::State {
let NestedRouteView { let NestedRouteView {
@ -930,17 +906,6 @@ where
state.outlets = outlets; state.outlets = outlets;
view.rebuild(&mut state.view); view.rebuild(&mut state.view);
} }
fn try_build(self) -> leptos::error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> leptos::error::Result<()> {
todo!()
}
} }
impl<Matcher, R> RenderHtml<R> for NestedRouteView<Matcher, R> impl<Matcher, R> RenderHtml<R> for NestedRouteView<Matcher, R>
@ -1119,7 +1084,6 @@ where
Rndr, Rndr,
>, >,
>; >;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let location = Loc::new().unwrap(); // TODO let location = Loc::new().unwrap(); // TODO
@ -1202,17 +1166,6 @@ where
} }
fn rebuild(self, state: &mut Self::State) {} fn rebuild(self, state: &mut Self::State) {}
fn try_build(self) -> leptos::error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> leptos::error::Result<()> {
todo!()
}
} }
impl<Rndr, Loc, FallbackFn, Fallback, Children> RenderHtml<Rndr> impl<Rndr, Loc, FallbackFn, Fallback, Children> RenderHtml<Rndr>

View file

@ -92,7 +92,6 @@ where
>, >,
>; >;
// TODO fallible state/error // TODO fallible state/error
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
// poll the future once immediately // poll the future once immediately
@ -145,17 +144,6 @@ where
} }
}); });
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<const TRANSITION: bool, Fal, Fut, Rndr> RenderHtml<Rndr> impl<const TRANSITION: bool, Fal, Fut, Rndr> RenderHtml<Rndr>

View file

@ -181,7 +181,6 @@ where
Rndr: Renderer, Rndr: Renderer,
{ {
type State = ElementState<At::State, Ch::State, Rndr>; type State = ElementState<At::State, Ch::State, Rndr>;
type FallibleState = ElementState<At::State, Ch::FallibleState, Rndr>;
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
let ElementState { let ElementState {
@ -203,31 +202,6 @@ where
rndr: PhantomData, rndr: PhantomData,
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
let el = Rndr::create_element(self.tag);
let attrs = self.attributes.build(&el);
let mut children = self.children.try_build()?;
children.mount(&el, None);
Ok(ElementState {
el,
attrs,
children,
rndr: PhantomData,
})
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
let ElementState {
attrs, children, ..
} = state;
self.attributes.rebuild(attrs);
self.children.try_rebuild(children)?;
Ok(())
}
} }
impl<E, At, Ch, Rndr> RenderHtml<Rndr> for HtmlElement<E, At, Ch, Rndr> impl<E, At, Ch, Rndr> RenderHtml<Rndr> for HtmlElement<E, At, Ch, Rndr>

View file

@ -48,7 +48,6 @@ where
Rndr: Renderer, Rndr: Renderer,
{ {
type State = View::State; type State = View::State;
type FallibleState = View::FallibleState;
fn build(self) -> Self::State { fn build(self) -> Self::State {
self.view.build() self.view.build()
@ -57,17 +56,6 @@ where
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
self.view.rebuild(state); self.view.rebuild(state);
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
self.view.try_build()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.view.try_rebuild(state)
}
} }
impl<Rndr, View> RenderHtml<Rndr> for Island<Rndr, View> impl<Rndr, View> RenderHtml<Rndr> for Island<Rndr, View>
@ -157,22 +145,10 @@ where
Rndr: Renderer, Rndr: Renderer,
{ {
type State = (); type State = ();
type FallibleState = Self::State;
fn build(self) -> Self::State {} fn build(self) -> Self::State {}
fn rebuild(self, _state: &mut Self::State) {} fn rebuild(self, _state: &mut Self::State) {}
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(())
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
Ok(())
}
} }
impl<Rndr, View> RenderHtml<Rndr> for IslandChildren<Rndr, View> impl<Rndr, View> RenderHtml<Rndr> for IslandChildren<Rndr, View>

View file

@ -30,22 +30,10 @@ pub fn doctype<R: Renderer>(value: &'static str) -> Doctype<R> {
impl<R: Renderer> Render<R> for Doctype<R> { impl<R: Renderer> Render<R> for Doctype<R> {
type State = (); type State = ();
type FallibleState = Self::State;
fn build(self) -> Self::State {} fn build(self) -> Self::State {}
fn rebuild(self, _state: &mut Self::State) {} fn rebuild(self, _state: &mut Self::State) {}
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(())
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
Ok(())
}
} }
impl<R> RenderHtml<R> for Doctype<R> impl<R> RenderHtml<R> for Doctype<R>

View file

@ -15,7 +15,6 @@ pub struct OcoStrState<R: Renderer> {
impl<R: Renderer> Render<R> for Oco<'static, str> { impl<R: Renderer> Render<R> for Oco<'static, str> {
type State = OcoStrState<R>; type State = OcoStrState<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self); let node = R::create_text_node(&self);
@ -29,18 +28,6 @@ impl<R: Renderer> Render<R> for Oco<'static, str> {
*str = self; *str = self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(<Self as Render<R>>::build(self))
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
<Self as Render<R>>::rebuild(self, state);
Ok(())
}
} }
impl<R> RenderHtml<R> for Oco<'static, str> impl<R> RenderHtml<R> for Oco<'static, str>

View file

@ -57,7 +57,7 @@ macro_rules! render_primitive {
where G: Deref<Target = $child_type> where G: Deref<Target = $child_type>
{ {
type State = [<ReadGuard $child_type:camel State>]<R>; type State = [<ReadGuard $child_type:camel State>]<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self.to_string()); let node = R::create_text_node(&self.to_string());
@ -71,15 +71,6 @@ macro_rules! render_primitive {
*this = *self; *this = *self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(self, state: &mut Self::FallibleState) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<G, R> RenderHtml<R> for ReadGuard<$child_type, G> impl<G, R> RenderHtml<R> for ReadGuard<$child_type, G>
@ -209,7 +200,6 @@ where
G: Deref<Target = String>, G: Deref<Target = String>,
{ {
type State = ReadGuardStringState<R>; type State = ReadGuardStringState<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self); let node = R::create_text_node(&self);
@ -227,18 +217,6 @@ where
str.push_str(&self); str.push_str(&self);
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<G, R> RenderHtml<R> for ReadGuard<String, G> impl<G, R> RenderHtml<R> for ReadGuard<String, G>

View file

@ -50,12 +50,9 @@ where
F: FnMut() -> V + 'static, F: FnMut() -> V + 'static,
V: Render<R>, V: Render<R>,
V::State: 'static, V::State: 'static,
V::FallibleState: 'static,
R: Renderer, R: Renderer,
{ {
type State = RenderEffectState<V::State>; type State = RenderEffectState<V::State>;
type FallibleState =
RenderEffectState<Result<V::FallibleState, Option<AnyError>>>;
#[track_caller] #[track_caller]
fn build(mut self) -> Self::State { fn build(mut self) -> Self::State {
@ -71,63 +68,10 @@ where
.into() .into()
} }
fn try_build(mut self) -> any_error::Result<Self::FallibleState> {
let parent = Observer::get();
let effect = RenderEffect::new({
move |prev| {
let value = self();
if let Some(mut state) = prev {
match state {
Ok(ref mut state) => {
if let Err(e) = value.try_rebuild(state) {
if let Some(parent) = &parent {
parent.mark_check();
}
return Err(Some(e));
}
}
Err(_) => {
if let Some(parent) = &parent {
parent.mark_check();
}
return value.try_build().map_err(Some);
}
}
state
} else {
value.try_build().map_err(Some)
}
}
});
effect
.with_value_mut(|inner| match inner {
Err(e) if e.is_some() => Err(e.take().unwrap()),
_ => Ok(()),
})
.expect("RenderEffect should run once synchronously")
.map(|_| effect.into())
}
#[track_caller] #[track_caller]
fn rebuild(self, _state: &mut Self::State) { fn rebuild(self, _state: &mut Self::State) {
// TODO rebuild // TODO rebuild
} }
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
if let Some(inner) = &mut state.0 {
inner
.with_value_mut(|value| match value {
Err(e) if e.is_some() => Err(e.take().unwrap()),
_ => Ok(()),
})
.unwrap_or(Ok(()))
} else {
Ok(())
}
}
} }
pub struct RenderEffectState<T: 'static>(Option<RenderEffect<T>>); pub struct RenderEffectState<T: 'static>(Option<RenderEffect<T>>);
@ -210,7 +154,7 @@ where
F: FnMut() -> V + Send + 'static, F: FnMut() -> V + Send + 'static,
V: RenderHtml<R>, V: RenderHtml<R>,
V::State: 'static, V::State: 'static,
V::FallibleState: 'static,
R: Renderer + 'static, R: Renderer + 'static,
{ {
type AsyncOutput = V::AsyncOutput; type AsyncOutput = V::AsyncOutput;
@ -266,7 +210,7 @@ where
F: FnMut() -> V + Send + 'static, F: FnMut() -> V + Send + 'static,
V: RenderHtml<R>, V: RenderHtml<R>,
V::State: 'static, V::State: 'static,
V::FallibleState: 'static,
R: Renderer + 'static, R: Renderer + 'static,
{ {
type Output<SomeNewAttr: Attribute<R>> = Self; type Output<SomeNewAttr: Attribute<R>> = Self;
@ -448,40 +392,27 @@ mod stable {
where where
V: Render<R> + Clone + Send + Sync + 'static, V: Render<R> + Clone + Send + Sync + 'static,
V::State: 'static, V::State: 'static,
V::FallibleState: 'static,
R: Renderer, R: Renderer,
{ {
type State = RenderEffectState<V::State>; type State = RenderEffectState<V::State>;
type FallibleState = RenderEffectState<
Result<V::FallibleState, Option<AnyError>>,
>;
#[track_caller] #[track_caller]
fn build(self) -> Self::State { fn build(self) -> Self::State {
(move || self.get()).build() (move || self.get()).build()
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
(move || self.get()).try_build()
}
#[track_caller] #[track_caller]
fn rebuild(self, _state: &mut Self::State) { fn rebuild(self, _state: &mut Self::State) {
// TODO rebuild // TODO rebuild
} }
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
(move || self.get()).try_rebuild(state)
}
} }
impl<V, R> RenderHtml<R> for $sig<V> impl<V, R> RenderHtml<R> for $sig<V>
where where
V: RenderHtml<R> + Clone + Send + Sync + 'static, V: RenderHtml<R> + Clone + Send + Sync + 'static,
V::State: 'static, V::State: 'static,
V::FallibleState: 'static,
R: Renderer + 'static, R: Renderer + 'static,
{ {
type AsyncOutput = Self; type AsyncOutput = Self;
@ -574,41 +505,27 @@ mod stable {
where where
V: Render<R> + Clone + 'static, V: Render<R> + Clone + 'static,
V::State: 'static, V::State: 'static,
V::FallibleState: 'static,
R: Renderer, R: Renderer,
{ {
type State = RenderEffectState<V::State>; type State = RenderEffectState<V::State>;
type FallibleState = RenderEffectState<
Result<V::FallibleState, Option<AnyError>>,
>;
#[track_caller] #[track_caller]
fn build(self) -> Self::State { fn build(self) -> Self::State {
(move || self.get()).build() (move || self.get()).build()
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
(move || self.get()).try_build()
}
#[track_caller] #[track_caller]
fn rebuild(self, _state: &mut Self::State) { fn rebuild(self, _state: &mut Self::State) {
// TODO rebuild // TODO rebuild
} }
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
(move || self.get()).try_rebuild(state)
}
} }
impl<V, R> RenderHtml<R> for $sig<V> impl<V, R> RenderHtml<R> for $sig<V>
where where
V: RenderHtml<R> + Clone + Send + Sync + 'static, V: RenderHtml<R> + Clone + Send + Sync + 'static,
V::State: 'static, V::State: 'static,
V::FallibleState: 'static,
R: Renderer + 'static, R: Renderer + 'static,
{ {
type AsyncOutput = Self; type AsyncOutput = Self;

View file

@ -68,7 +68,6 @@ where
R: Renderer, R: Renderer,
{ {
type State = OwnedViewState<T::State, R>; type State = OwnedViewState<T::State, R>;
type FallibleState = OwnedViewState<T::FallibleState, R>;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let state = self.owner.with(|| self.view.build()); let state = self.owner.with(|| self.view.build());
@ -80,17 +79,6 @@ where
owner.with(|| view.rebuild(&mut state.state)); owner.with(|| view.rebuild(&mut state.state));
state.owner = owner; state.owner = owner;
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<T, R> RenderHtml<R> for OwnedView<T, R> impl<T, R> RenderHtml<R> for OwnedView<T, R>

View file

@ -261,7 +261,6 @@ where
R: Renderer + 'static, R: Renderer + 'static,
{ {
type State = AnyViewState<R>; type State = AnyViewState<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
(self.build)(self.value) (self.build)(self.value)
@ -270,17 +269,6 @@ where
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
(self.rebuild)(self.type_id, self.value, state) (self.rebuild)(self.type_id, self.value, state)
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<R> RenderHtml<R> for AnyView<R> impl<R> RenderHtml<R> for AnyView<R>

View file

@ -27,7 +27,6 @@ where
Rndr: Renderer, Rndr: Renderer,
{ {
type State = EitherState<A::State, B::State, Rndr>; type State = EitherState<A::State, B::State, Rndr>;
type FallibleState = EitherState<A::FallibleState, B::FallibleState, Rndr>;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let marker = Rndr::create_placeholder(); let marker = Rndr::create_placeholder();
@ -62,17 +61,6 @@ where
} }
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<A, B, Rndr> Mountable<Rndr> for EitherState<A, B, Rndr> impl<A, B, Rndr> Mountable<Rndr> for EitherState<A, B, Rndr>
@ -229,8 +217,6 @@ where
{ {
type State = EitherKeepAliveState<A::State, B::State, Rndr>; type State = EitherKeepAliveState<A::State, B::State, Rndr>;
type FallibleState = ();
fn build(self) -> Self::State { fn build(self) -> Self::State {
let marker = Rndr::create_placeholder(); let marker = Rndr::create_placeholder();
let showing_b = self.show_b; let showing_b = self.show_b;
@ -282,17 +268,6 @@ where
} }
state.showing_b = self.show_b; state.showing_b = self.show_b;
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<A, B, Rndr> RenderHtml<Rndr> for EitherKeepAlive<A, B> impl<A, B, Rndr> RenderHtml<Rndr> for EitherKeepAlive<A, B>
@ -452,7 +427,7 @@ macro_rules! tuples {
Rndr: Renderer Rndr: Renderer
{ {
type State = [<EitherOf $num State>]<$($ty,)* Rndr>; type State = [<EitherOf $num State>]<$($ty,)* Rndr>;
type FallibleState = [<EitherOf $num State>]<$($ty,)* Rndr>;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let marker = Rndr::create_placeholder(); let marker = Rndr::create_placeholder();
@ -483,18 +458,6 @@ macro_rules! tuples {
// and store the new state // and store the new state
state.state = new_state; state.state = new_state;
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<Rndr, $($ty,)*> RenderHtml<Rndr> for [<EitherOf $num>]<$($ty,)*> impl<Rndr, $($ty,)*> RenderHtml<Rndr> for [<EitherOf $num>]<$($ty,)*>

View file

@ -21,7 +21,6 @@ where
E: Into<AnyError> + 'static, E: Into<AnyError> + 'static,
{ {
type State = ResultState<T::State, R>; type State = ResultState<T::State, R>;
type FallibleState = T::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let placeholder = R::create_placeholder(); let placeholder = R::create_placeholder();
@ -56,17 +55,6 @@ where
} }
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
/// View state for a `Result<_, _>` view. /// View state for a `Result<_, _>` view.
@ -209,270 +197,3 @@ where
ResultState { placeholder, state } ResultState { placeholder, state }
} }
} }
/*
pub trait TryCatchBoundary<Fal, FalFn, Rndr>
where
Self: Sized + Render<Rndr>,
Fal: Render<Rndr>,
FalFn: FnMut(AnyError) -> Fal,
Rndr: Renderer,
{
fn catch(self, fallback: FalFn) -> Try<Self, Fal, FalFn, Rndr>;
}
impl<T, Fal, FalFn, Rndr> TryCatchBoundary<Fal, FalFn, Rndr> for T
where
T: Sized + Render<Rndr>,
Fal: Render<Rndr>,
FalFn: FnMut(AnyError) -> Fal,
Rndr: Renderer,
{
fn catch(self, fallback: FalFn) -> Try<Self, Fal, FalFn, Rndr> {
Try::new(fallback, self)
}
}
pub struct Try<T, Fal, FalFn, Rndr>
where
T: Render<Rndr>,
Fal: Render<Rndr>,
FalFn: FnMut(AnyError) -> Fal,
Rndr: Renderer,
{
child: T,
fal: FalFn,
ty: PhantomData<Rndr>,
}
impl<T, Fal, FalFn, Rndr> Try<T, Fal, FalFn, Rndr>
where
T: Render<Rndr>,
Fal: Render<Rndr>,
FalFn: FnMut(AnyError) -> Fal,
Rndr: Renderer,
{
pub fn new(fallback: FalFn, child: T) -> Self {
Self {
child,
fal: fallback,
ty: PhantomData,
}
}
}
impl<T, Fal, FalFn, Rndr> Render<Rndr> for Try<T, Fal, FalFn, Rndr>
where
T: Render<Rndr>,
Fal: Render<Rndr>,
FalFn: FnMut(AnyError) -> Fal,
Rndr: Renderer,
{
type State = TryState<T, Fal, Rndr>;
type FallibleState = Self::State;
fn build(mut self) -> Self::State {
let inner = match self.child.try_build() {
Ok(inner) => TryStateState::Success(Some(inner)),
Err(e) => TryStateState::InitialFail((self.fal)(e).build()),
};
let marker = Rndr::create_placeholder();
TryState { inner, marker }
}
fn rebuild(mut self, state: &mut Self::State) {
let marker = state.marker.as_ref();
let res = match &mut state.inner {
TryStateState::Success(old) => {
let old_unwrapped =
old.as_mut().expect("children removed before expected");
if let Err(e) = self.child.try_rebuild(old_unwrapped) {
old_unwrapped.unmount();
let mut new_state = (self.fal)(e).build();
Rndr::mount_before(&mut new_state, marker);
Some(Err((old.take(), new_state)))
} else {
None
}
}
TryStateState::InitialFail(old) => match self.child.try_build() {
Err(e) => {
(self.fal)(e).rebuild(old);
None
}
Ok(mut new_state) => {
old.unmount();
Rndr::mount_before(&mut new_state, marker);
Some(Ok(new_state))
}
},
TryStateState::SubsequentFail { fallback, .. } => {
match self.child.try_build() {
Err(e) => {
(self.fal)(e).rebuild(fallback);
None
}
Ok(mut new_children) => {
fallback.unmount();
Rndr::mount_before(&mut new_children, marker);
Some(Ok(new_children))
}
}
}
};
match res {
Some(Ok(new_children)) => {
state.inner = TryStateState::Success(Some(new_children))
}
Some(Err((_children, fallback))) => {
state.inner = TryStateState::SubsequentFail {
_children,
fallback,
}
}
None => {}
}
}
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
}
// TODO RenderHtml implementation for ErrorBoundary
impl<T, Fal, FalFn, Rndr> RenderHtml<Rndr> for Try<T, Fal, FalFn, Rndr>
where
T: RenderHtml<Rndr>,
Fal: RenderHtml<Rndr>,
FalFn: FnMut(AnyError) -> Fal,
Rndr: Renderer,
{
type AsyncOutput = Ready<Try<T::AsyncOutput, Fal, FalFn, Rndr>>;
const MIN_LENGTH: usize = Fal::MIN_LENGTH;
async fn resolve(self) -> Self::AsyncOutput {
todo!()
}
fn to_html_with_buf(
self,
_buf: &mut String,
_position: &mut super::Position,
) {
todo!()
}
fn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
self,
_buf: &mut crate::ssr::StreamBuilder,
_position: &mut super::Position,
) where
Self: Sized,
{
todo!()
}
fn hydrate<const FROM_SERVER: bool>(
self,
_cursor: &crate::hydration::Cursor<Rndr>,
_position: &super::PositionState,
) -> Self::State {
todo!()
}
}
pub struct TryState<T, Fal, Rndr>
where
T: Render<Rndr>,
Fal: Render<Rndr>,
Rndr: Renderer,
{
inner: TryStateState<T, Fal, Rndr>,
marker: Rndr::Placeholder,
}
enum TryStateState<T, Fal, Rndr>
where
T: Render<Rndr>,
Fal: Render<Rndr>,
Rndr: Renderer,
{
Success(Option<T::FallibleState>),
InitialFail(Fal::State),
SubsequentFail {
// they exist here only to be kept alive
// this is important if the children are holding some reactive state that
// caused the error boundary to be triggered in the first place
_children: Option<T::FallibleState>,
fallback: Fal::State,
},
}
impl<T, Fal, Rndr> Mountable<Rndr> for TryState<T, Fal, Rndr>
where
T: Render<Rndr>,
Fal: Render<Rndr>,
Rndr: Renderer,
{
fn unmount(&mut self) {
match &mut self.inner {
TryStateState::Success(m) => m
.as_mut()
.expect("children removed before expected")
.unmount(),
TryStateState::InitialFail(m) => m.unmount(),
TryStateState::SubsequentFail { fallback, .. } => {
fallback.unmount()
}
}
self.marker.unmount();
}
fn mount(
&mut self,
parent: &<Rndr as Renderer>::Element,
marker: Option<&<Rndr as Renderer>::Node>,
) {
self.marker.mount(parent, marker);
match &mut self.inner {
TryStateState::Success(m) => m
.as_mut()
.expect("children removed before expected")
.mount(parent, Some(self.marker.as_ref())),
TryStateState::InitialFail(m) => {
m.mount(parent, Some(self.marker.as_ref()))
}
TryStateState::SubsequentFail { fallback, .. } => {
fallback.mount(parent, Some(self.marker.as_ref()))
}
}
}
fn insert_before_this(
&self,
parent: &<Rndr as Renderer>::Element,
child: &mut dyn Mountable<Rndr>,
) -> bool {
match &self.inner {
TryStateState::Success(m) => m
.as_ref()
.expect("children removed before expected")
.insert_before_this(parent, child),
TryStateState::InitialFail(m) => {
m.insert_before_this(parent, child)
}
TryStateState::SubsequentFail { fallback, .. } => {
fallback.insert_before_this(parent, child)
}
}
}
}*/

View file

@ -19,7 +19,6 @@ where
R: Renderer, R: Renderer,
{ {
type State = OptionState<T::State, R>; type State = OptionState<T::State, R>;
type FallibleState = OptionState<T::FallibleState, R>;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let placeholder = R::create_placeholder(); let placeholder = R::create_placeholder();
@ -49,35 +48,6 @@ where
} }
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
match self {
None => {
let placeholder = R::create_placeholder();
Ok(OptionState {
placeholder,
state: None,
})
}
Some(inner) => match inner.try_build() {
Err(e) => Err(e),
Ok(inner) => {
let placeholder = R::create_placeholder();
Ok(OptionState {
placeholder,
state: Some(inner),
})
}
},
}
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<T, R> RenderHtml<R> for Option<T> impl<T, R> RenderHtml<R> for Option<T>
@ -204,7 +174,6 @@ where
R: Renderer, R: Renderer,
{ {
type State = VecState<T::State, R>; type State = VecState<T::State, R>;
type FallibleState = VecState<T::FallibleState, R>;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let marker = R::create_placeholder(); let marker = R::create_placeholder();
@ -255,22 +224,6 @@ where
old.append(&mut adds); old.append(&mut adds);
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
let states = self
.into_iter()
.map(T::try_build)
.collect::<Result<_, _>>()?;
let marker = R::create_placeholder();
Ok(VecState { states, marker })
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
pub struct VecState<T, R> pub struct VecState<T, R>

View file

@ -74,7 +74,6 @@ where
{ {
type State = KeyedState<K, V, Rndr>; type State = KeyedState<K, V, Rndr>;
// TODO fallible state and try_build()/try_rebuild() here // TODO fallible state and try_build()/try_rebuild() here
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let items = self.items.into_iter(); let items = self.items.into_iter();
@ -128,17 +127,6 @@ where
*hashed_items = new_hashed_items; *hashed_items = new_hashed_items;
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<T, I, K, KF, VF, V, Rndr> RenderHtml<Rndr> impl<T, I, K, KF, VF, V, Rndr> RenderHtml<Rndr>

View file

@ -26,21 +26,11 @@ pub trait Render<R: Renderer>: Sized {
/// and the previous string, to allow for diffing between updates. /// and the previous string, to allow for diffing between updates.
type State: Mountable<R>; type State: Mountable<R>;
// TODO remove this, the other ErrorBoundary way is better
type FallibleState: Mountable<R>;
/// Creates the view for the first time, without hydrating from existing HTML. /// Creates the view for the first time, without hydrating from existing HTML.
fn build(self) -> Self::State; fn build(self) -> Self::State;
/// Updates the view with new data. /// Updates the view with new data.
fn rebuild(self, state: &mut Self::State); fn rebuild(self, state: &mut Self::State);
fn try_build(self) -> any_error::Result<Self::FallibleState>;
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()>;
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

View file

@ -47,7 +47,7 @@ macro_rules! render_primitive {
impl<R: Renderer> Render<R> for $child_type { impl<R: Renderer> Render<R> for $child_type {
type State = [<$child_type:camel State>]<R>; type State = [<$child_type:camel State>]<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self.to_string()); let node = R::create_text_node(&self.to_string());
@ -61,15 +61,6 @@ macro_rules! render_primitive {
*this = self; *this = self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(self, state: &mut Self::FallibleState) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<R> RenderHtml<R> for $child_type impl<R> RenderHtml<R> for $child_type

View file

@ -132,7 +132,6 @@ where
R::Text: Mountable<R>, R::Text: Mountable<R>,
{ {
type State = Option<R::Text>; type State = Option<R::Text>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
// a view state has to be returned so it can be mounted // a view state has to be returned so it can be mounted
@ -141,18 +140,6 @@ where
// This type is specified as static, so no rebuilding is done. // This type is specified as static, so no rebuilding is done.
fn rebuild(self, _state: &mut Self::State) {} fn rebuild(self, _state: &mut Self::State) {}
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(Render::<R>::build(self))
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
Render::<R>::rebuild(self, state);
Ok(())
}
} }
impl<const V: &'static str, R> RenderHtml<R> for Static<V> impl<const V: &'static str, R> RenderHtml<R> for Static<V>

View file

@ -19,7 +19,6 @@ pub struct StrState<'a, R: Renderer> {
impl<'a, R: Renderer> Render<R> for &'a str { impl<'a, R: Renderer> Render<R> for &'a str {
type State = StrState<'a, R>; type State = StrState<'a, R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(self); let node = R::create_text_node(self);
@ -33,18 +32,6 @@ impl<'a, R: Renderer> Render<R> for &'a str {
*str = self; *str = self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<'a, R> RenderHtml<R> for &'a str impl<'a, R> RenderHtml<R> for &'a str
@ -152,7 +139,6 @@ pub struct StringState<R: Renderer> {
impl<R: Renderer> Render<R> for String { impl<R: Renderer> Render<R> for String {
type State = StringState<R>; type State = StringState<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self); let node = R::create_text_node(&self);
@ -166,18 +152,6 @@ impl<R: Renderer> Render<R> for String {
*str = self; *str = self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<R> RenderHtml<R> for String impl<R> RenderHtml<R> for String
@ -256,7 +230,6 @@ pub struct RcStrState<R: Renderer> {
impl<R: Renderer> Render<R> for Rc<str> { impl<R: Renderer> Render<R> for Rc<str> {
type State = RcStrState<R>; type State = RcStrState<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self); let node = R::create_text_node(&self);
@ -270,18 +243,6 @@ impl<R: Renderer> Render<R> for Rc<str> {
*str = self; *str = self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
// can't Send an Rc<str> between threads, so can't implement async HTML rendering that might need // can't Send an Rc<str> between threads, so can't implement async HTML rendering that might need
@ -365,7 +326,6 @@ pub struct ArcStrState<R: Renderer> {
impl<R: Renderer> Render<R> for Arc<str> { impl<R: Renderer> Render<R> for Arc<str> {
type State = ArcStrState<R>; type State = ArcStrState<R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self); let node = R::create_text_node(&self);
@ -379,18 +339,6 @@ impl<R: Renderer> Render<R> for Arc<str> {
*str = self; *str = self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<R> RenderHtml<R> for Arc<str> impl<R> RenderHtml<R> for Arc<str>
@ -471,7 +419,6 @@ pub struct CowStrState<'a, R: Renderer> {
impl<'a, R: Renderer> Render<R> for Cow<'a, str> { impl<'a, R: Renderer> Render<R> for Cow<'a, str> {
type State = CowStrState<'a, R>; type State = CowStrState<'a, R>;
type FallibleState = Self::State;
fn build(self) -> Self::State { fn build(self) -> Self::State {
let node = R::create_text_node(&self); let node = R::create_text_node(&self);
@ -485,18 +432,6 @@ impl<'a, R: Renderer> Render<R> for Cow<'a, str> {
*str = self; *str = self;
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(self.build())
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.rebuild(state);
Ok(())
}
} }
impl<'a, R> RenderHtml<R> for Cow<'a, str> impl<'a, R> RenderHtml<R> for Cow<'a, str>

View file

@ -37,7 +37,6 @@ where
R: DomRenderer, R: DomRenderer,
{ {
type State = V::State; type State = V::State;
type FallibleState = V::FallibleState;
// TODO try_build/try_rebuild() // TODO try_build/try_rebuild()
@ -51,17 +50,6 @@ where
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
self.view.rebuild(state) self.view.rebuild(state)
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
todo!()
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
todo!()
}
} }
impl<V, R> RenderHtml<R> for ViewTemplate<V, R> impl<V, R> RenderHtml<R> for ViewTemplate<V, R>

View file

@ -19,22 +19,10 @@ use std::{
impl<R: Renderer> Render<R> for () { impl<R: Renderer> Render<R> for () {
type State = (); type State = ();
type FallibleState = Self::State;
fn build(self) -> Self::State {} fn build(self) -> Self::State {}
fn rebuild(self, _state: &mut Self::State) {} fn rebuild(self, _state: &mut Self::State) {}
fn try_build(self) -> any_error::Result<Self::FallibleState> {
Ok(())
}
fn try_rebuild(
self,
_state: &mut Self::FallibleState,
) -> any_error::Result<()> {
Ok(())
}
} }
impl<R> RenderHtml<R> for () impl<R> RenderHtml<R> for ()
@ -111,7 +99,6 @@ impl ToTemplate for () {
impl<A: Render<R>, R: Renderer> Render<R> for (A,) { impl<A: Render<R>, R: Renderer> Render<R> for (A,) {
type State = A::State; type State = A::State;
type FallibleState = A::FallibleState;
fn build(self) -> Self::State { fn build(self) -> Self::State {
self.0.build() self.0.build()
@ -120,17 +107,6 @@ impl<A: Render<R>, R: Renderer> Render<R> for (A,) {
fn rebuild(self, state: &mut Self::State) { fn rebuild(self, state: &mut Self::State) {
self.0.rebuild(state) self.0.rebuild(state)
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
self.0.try_build()
}
fn try_rebuild(
self,
state: &mut Self::FallibleState,
) -> any_error::Result<()> {
self.0.try_rebuild(state)
}
} }
impl<A, R> RenderHtml<R> for (A,) impl<A, R> RenderHtml<R> for (A,)
@ -226,7 +202,7 @@ macro_rules! impl_view_for_tuples {
Rndr: Renderer Rndr: Renderer
{ {
type State = ($first::State, $($ty::State,)*); type State = ($first::State, $($ty::State,)*);
type FallibleState = ($first::FallibleState, $($ty::FallibleState,)*);
fn build(self) -> Self::State { fn build(self) -> Self::State {
#[allow(non_snake_case)] #[allow(non_snake_case)]
@ -245,25 +221,6 @@ macro_rules! impl_view_for_tuples {
$([<$ty:lower>].rebuild([<view_ $ty:lower>]));* $([<$ty:lower>].rebuild([<view_ $ty:lower>]));*
} }
} }
fn try_build(self) -> any_error::Result<Self::FallibleState> {
#[allow(non_snake_case)]
let ($first, $($ty,)*) = self;
Ok((
$first.try_build()?,
$($ty.try_build()?),*
))
}
fn try_rebuild(self, state: &mut Self::FallibleState) -> any_error::Result<()> {
paste::paste! {
let ([<$first:lower>], $([<$ty:lower>],)*) = self;
let ([<view_ $first:lower>], $([<view_ $ty:lower>],)*) = state;
[<$first:lower>].try_rebuild([<view_ $first:lower>])?;
$([<$ty:lower>].try_rebuild([<view_ $ty:lower>])?);*
}
Ok(())
}
} }
impl<$first, $($ty),*, Rndr> RenderHtml<Rndr> for ($first, $($ty,)*) impl<$first, $($ty),*, Rndr> RenderHtml<Rndr> for ($first, $($ty,)*)