diff --git a/tachys/src/reactive_graph/guards.rs b/tachys/src/reactive_graph/guards.rs index 833cadcb7..39a09ca39 100644 --- a/tachys/src/reactive_graph/guards.rs +++ b/tachys/src/reactive_graph/guards.rs @@ -1,4 +1,8 @@ -//! Implements the [`Render`] and [`RenderHtml`] traits for signal guard types. +/* The implementations here are no longer valid because the read guards are not Send. + * If we switch to using some kind of Send async lock, it would be possible to restore them. + * + * + * //! Implements the [`Render`] and [`RenderHtml`] traits for signal guard types. use crate::{ html::attribute::Attribute, @@ -21,68 +25,67 @@ use std::{ }, ops::Deref, }; - // any changes here should also be made in src/view/primitives.rs // TODO should also apply to mapped signal read guards macro_rules! render_primitive { ($($child_type:ty),* $(,)?) => { $( - paste::paste! { - pub struct [](R::Text, $child_type) where R: Renderer; + paste::paste! { + pub struct [](R::Text, $child_type) where R: Renderer; - impl<'a, R: Renderer> Mountable for [] { - fn unmount(&mut self) { - self.0.unmount() - } + impl<'a, R: Renderer> Mountable for [] { + fn unmount(&mut self) { + self.0.unmount() + } - fn mount( - &mut self, - parent: &::Element, - marker: Option<&::Node>, - ) { - R::insert_node(parent, self.0.as_ref(), marker); - } + fn mount( + &mut self, + parent: &::Element, + marker: Option<&::Node>, + ) { + R::insert_node(parent, self.0.as_ref(), marker); + } - fn insert_before_this( - &self, - parent: &::Element, - child: &mut dyn Mountable, - ) -> bool { - child.mount(parent, Some(self.0.as_ref())); - true - } - } + fn insert_before_this( + &self, + parent: &::Element, + child: &mut dyn Mountable, + ) -> bool { + child.mount(parent, Some(self.0.as_ref())); + true + } + } - impl Render for ReadGuard<$child_type, G> + impl Render for ReadGuard<$child_type, G> where G: Deref { - type State = []; + type State = []; - fn build(self) -> Self::State { - let node = R::create_text_node(&self.to_string()); - [](node, *self) - } + fn build(self) -> Self::State { + let node = R::create_text_node(&self.to_string()); + [](node, *self) + } - fn rebuild(self, state: &mut Self::State) { - let [](node, this) = state; - if &self != this { - R::set_text(node, &self.to_string()); - *this = *self; - } - } - } + fn rebuild(self, state: &mut Self::State) { + let [](node, this) = state; + if &self != this { + R::set_text(node, &self.to_string()); + *this = *self; + } + } + } impl AddAnyAttr for ReadGuard<$child_type, G> - where - R: Renderer, + where + R: Renderer, G: Deref + Send { type Output> = ReadGuard<$child_type, G>; fn add_any_attr>( self, - attr: NewAttr, + _attr: NewAttr, ) -> Self::Output where Self::Output: RenderHtml, @@ -93,76 +96,76 @@ macro_rules! render_primitive { } } - impl RenderHtml for ReadGuard<$child_type, G> - where - R: Renderer, + impl RenderHtml for ReadGuard<$child_type, G> + where + R: Renderer, G: Deref + Send - { + { type AsyncOutput = Self; - const MIN_LENGTH: usize = 0; + const MIN_LENGTH: usize = 0; - fn to_html_with_buf(self, buf: &mut String, position: &mut Position) { - // add a comment node to separate from previous sibling, if any - if matches!(position, Position::NextChildAfterText) { - buf.push_str("") - } - _ = write!(buf, "{}", self); - *position = Position::NextChildAfterText; - } + fn to_html_with_buf(self, buf: &mut String, position: &mut Position) { + // add a comment node to separate from previous sibling, if any + if matches!(position, Position::NextChildAfterText) { + buf.push_str("") + } + _ = write!(buf, "{}", self); + *position = Position::NextChildAfterText; + } - fn hydrate( - self, - cursor: &Cursor, - position: &PositionState, - ) -> Self::State { - if position.get() == Position::FirstChild { - cursor.child(); - } else { - cursor.sibling(); - } + fn hydrate( + self, + cursor: &Cursor, + position: &PositionState, + ) -> Self::State { + if position.get() == Position::FirstChild { + cursor.child(); + } else { + cursor.sibling(); + } - // separating placeholder marker comes before text node - if matches!(position.get(), Position::NextChildAfterText) { - cursor.sibling(); - } + // separating placeholder marker comes before text node + if matches!(position.get(), Position::NextChildAfterText) { + cursor.sibling(); + } - let node = cursor.current(); - let node = R::Text::cast_from(node) - .expect("couldn't cast text node from node"); + let node = cursor.current(); + let node = R::Text::cast_from(node) + .expect("couldn't cast text node from node"); - if !FROM_SERVER { - R::set_text(&node, &self.to_string()); - } - position.set(Position::NextChildAfterText); + if !FROM_SERVER { + R::set_text(&node, &self.to_string()); + } + position.set(Position::NextChildAfterText); - [](node, *self) - } + [](node, *self) + } async fn resolve(self) -> Self::AsyncOutput { self } - } + } - impl<'a, G> ToTemplate for ReadGuard<$child_type, G> + impl<'a, G> ToTemplate for ReadGuard<$child_type, G> { - const TEMPLATE: &'static str = " "; + const TEMPLATE: &'static str = " "; - fn to_template( - buf: &mut String, - _class: &mut String, - _style: &mut String, - _inner_html: &mut String, - position: &mut Position, - ) { - if matches!(*position, Position::NextChildAfterText) { - buf.push_str("") - } - buf.push(' '); - *position = Position::NextChildAfterText; - } - } - } + fn to_template( + buf: &mut String, + _class: &mut String, + _style: &mut String, + _inner_html: &mut String, + position: &mut Position, + ) { + if matches!(*position, Position::NextChildAfterText) { + buf.push_str("") + } + buf.push(' '); + *position = Position::NextChildAfterText; + } + } + } )* }; } @@ -323,4 +326,4 @@ impl Mountable for ReadGuardStringState { child.mount(parent, Some(self.node.as_ref())); true } -} +}*/