Skip to content

Commit

Permalink
Add Send to all output types
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston authored and bodil committed May 28, 2019
1 parent 62dd064 commit 8c34045
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion examples/iron/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Modifier<Response> for Html {
// argument of the type that the element that you're inserting it into expects,
// which in the case of `<body>` is `FlowContent`, not just `Node`, so you can't
// pass it a `DOMTree<T>` or you'll get a type error.
fn doc<T: OutputType + 'static>(tree: Box<dyn FlowContent<T>>) -> DOMTree<T> {
fn doc<T: OutputType + 'static + Send>(tree: Box<dyn FlowContent<T>>) -> DOMTree<T> {
html!(
<html>
<head>
Expand Down
16 changes: 8 additions & 8 deletions macros/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Declare {
}

quote!(
pub struct #elem_name<T> where T: crate::OutputType {
pub struct #elem_name<T> where T: crate::OutputType + Send {
pub attrs: #attr_type_name,
pub data_attributes: Vec<(&'static str, String)>,
pub events: T::Events,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Declare {
}

quote!(
impl<T> #elem_name<T> where T: crate::OutputType {
impl<T> #elem_name<T> where T: crate::OutputType + Send {
pub fn new(#args) -> Self {
#elem_name {
events: T::Events::default(),
Expand Down Expand Up @@ -197,7 +197,7 @@ impl Declare {
let elem_name = self.elem_name();
let vnode = self.impl_vnode();
quote!(
impl<T> crate::dom::Node<T> for #elem_name<T> where T: crate::OutputType {
impl<T> crate::dom::Node<T> for #elem_name<T> where T: crate::OutputType + Send {
fn vnode(&'_ mut self) -> crate::dom::VNode<'_, T> {
#vnode
}
Expand Down Expand Up @@ -225,7 +225,7 @@ impl Declare {
}

quote!(
impl<T> crate::dom::Element<T> for #elem_name<T> where T: crate::OutputType {
impl<T> crate::dom::Element<T> for #elem_name<T> where T: crate::OutputType + Send {
fn name() -> &'static str {
#name
}
Expand Down Expand Up @@ -256,7 +256,7 @@ impl Declare {
for t in &self.traits {
let name = t.clone();
body.extend(quote!(
impl<T> #name<T> for #elem_name<T> where T: crate::OutputType {}
impl<T> #name<T> for #elem_name<T> where T: crate::OutputType + Send {}
));
}
body
Expand All @@ -265,15 +265,15 @@ impl Declare {
fn impl_into_iter(&self) -> TokenStream {
let elem_name = self.elem_name();
quote!(
impl<T> IntoIterator for #elem_name<T> where T: crate::OutputType {
impl<T> IntoIterator for #elem_name<T> where T: crate::OutputType + Send {
type Item = #elem_name<T>;
type IntoIter = std::vec::IntoIter<#elem_name<T>>;
fn into_iter(self) -> Self::IntoIter {
vec![self].into_iter()
}
}

impl<T> IntoIterator for Box<#elem_name<T>> where T: crate::OutputType {
impl<T> IntoIterator for Box<#elem_name<T>> where T: crate::OutputType + Send {
type Item = Box<#elem_name<T>>;
type IntoIter = std::vec::IntoIter<Box<#elem_name<T>>>;
fn into_iter(self) -> Self::IntoIter {
Expand Down Expand Up @@ -348,7 +348,7 @@ impl Declare {
quote!(
impl<T> std::fmt::Display for #elem_name<T>
where
T: crate::OutputType,
T: crate::OutputType + Send,
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(f, "<{}", #name)?;
Expand Down
38 changes: 19 additions & 19 deletions typed-html/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct VElement<'a, T: OutputType + 'a> {
/// [TextNode]: struct.TextNode.html
/// [elements]: ../elements/index.html
/// [vnode]: #tymethod.vnode
pub trait Node<T: OutputType>: Display {
pub trait Node<T: OutputType + Send>: Display + Send {
/// Render the node into a [`VNode`][VNode] tree.
///
/// [VNode]: enum.VNode.html
Expand All @@ -75,7 +75,7 @@ pub trait Node<T: OutputType>: Display {

impl<T> IntoIterator for Box<dyn Node<T>>
where
T: OutputType,
T: OutputType + Send,
{
type Item = Box<dyn Node<T>>;
type IntoIter = std::vec::IntoIter<Box<dyn Node<T>>>;
Expand All @@ -90,7 +90,7 @@ where
/// All [HTML elements][elements] implement this.
///
/// [elements]: ../elements/index.html
pub trait Element<T: OutputType>: Node<T> {
pub trait Element<T: OutputType + Send>: Node<T> {
/// Get the name of the element.
fn name() -> &'static str;
/// Get a list of the attribute names for this element.
Expand All @@ -112,7 +112,7 @@ pub trait Element<T: OutputType>: Node<T> {
}

/// An HTML text node.
pub struct TextNode<T: OutputType>(String, PhantomData<T>);
pub struct TextNode<T: OutputType + Send>(String, PhantomData<T>);

/// Macro for creating text nodes.
///
Expand Down Expand Up @@ -146,7 +146,7 @@ macro_rules! text {

/// An unsafe HTML text node.
/// This is like TextNode, but no escaping will be performed when this node is displayed.
pub struct UnsafeTextNode<T: OutputType>(String, PhantomData<T>);
pub struct UnsafeTextNode<T: OutputType + Send>(String, PhantomData<T>);

/// Macro for creating unescaped text nodes.
///
Expand Down Expand Up @@ -186,7 +186,7 @@ macro_rules! unsafe_text {
};
}

impl<T: OutputType> TextNode<T> {
impl<T: OutputType + Send> TextNode<T> {
/// Construct a text node.
///
/// The preferred way to construct a text node is with the [`text!()`][text]
Expand All @@ -198,19 +198,19 @@ impl<T: OutputType> TextNode<T> {
}
}

impl<T: OutputType> Display for TextNode<T> {
impl<T: OutputType + Send> Display for TextNode<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
f.write_str(&encode_minimal(&self.0))
}
}

impl<T: OutputType> Node<T> for TextNode<T> {
impl<T: OutputType + Send> Node<T> for TextNode<T> {
fn vnode(&'_ mut self) -> VNode<'_, T> {
VNode::Text(&self.0)
}
}

impl<T: OutputType> IntoIterator for TextNode<T> {
impl<T: OutputType + Send> IntoIterator for TextNode<T> {
type Item = TextNode<T>;
type IntoIter = std::vec::IntoIter<TextNode<T>>;

Expand All @@ -219,7 +219,7 @@ impl<T: OutputType> IntoIterator for TextNode<T> {
}
}

impl<T: OutputType> IntoIterator for Box<TextNode<T>> {
impl<T: OutputType + Send> IntoIterator for Box<TextNode<T>> {
type Item = Box<TextNode<T>>;
type IntoIter = std::vec::IntoIter<Box<TextNode<T>>>;

Expand All @@ -228,10 +228,10 @@ impl<T: OutputType> IntoIterator for Box<TextNode<T>> {
}
}

impl<T: OutputType> FlowContent<T> for TextNode<T> {}
impl<T: OutputType> PhrasingContent<T> for TextNode<T> {}
impl<T: OutputType + Send> FlowContent<T> for TextNode<T> {}
impl<T: OutputType + Send> PhrasingContent<T> for TextNode<T> {}

impl<T: OutputType> UnsafeTextNode<T> {
impl<T: OutputType + Send> UnsafeTextNode<T> {
/// Construct a unsafe text node.
///
/// The preferred way to construct a unsafe text node is with the [`unsafe_text!()`][unsafe_text]
Expand All @@ -243,19 +243,19 @@ impl<T: OutputType> UnsafeTextNode<T> {
}
}

impl<T: OutputType> Display for UnsafeTextNode<T> {
impl<T: OutputType + Send> Display for UnsafeTextNode<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
f.write_str(&self.0)
}
}

impl<T: OutputType> Node<T> for UnsafeTextNode<T> {
impl<T: OutputType + Send> Node<T> for UnsafeTextNode<T> {
fn vnode(&'_ mut self) -> VNode<'_, T> {
VNode::UnsafeText(&self.0)
}
}

impl<T: OutputType> IntoIterator for UnsafeTextNode<T> {
impl<T: OutputType + Send> IntoIterator for UnsafeTextNode<T> {
type Item = UnsafeTextNode<T>;
type IntoIter = std::vec::IntoIter<UnsafeTextNode<T>>;

Expand All @@ -264,7 +264,7 @@ impl<T: OutputType> IntoIterator for UnsafeTextNode<T> {
}
}

impl<T: OutputType> IntoIterator for Box<UnsafeTextNode<T>> {
impl<T: OutputType + Send> IntoIterator for Box<UnsafeTextNode<T>> {
type Item = Box<UnsafeTextNode<T>>;
type IntoIter = std::vec::IntoIter<Box<UnsafeTextNode<T>>>;

Expand All @@ -273,5 +273,5 @@ impl<T: OutputType> IntoIterator for Box<UnsafeTextNode<T>> {
}
}

impl<T: OutputType> FlowContent<T> for UnsafeTextNode<T> {}
impl<T: OutputType> PhrasingContent<T> for UnsafeTextNode<T> {}
impl<T: OutputType + Send> FlowContent<T> for UnsafeTextNode<T> {}
impl<T: OutputType + Send> PhrasingContent<T> for UnsafeTextNode<T> {}
4 changes: 2 additions & 2 deletions typed-html/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ macro_rules! marker_trait {
};

($trait:ident, $parent:ident) => {
pub trait $trait<T: OutputType>: $parent<T> {}
pub trait $trait<T: OutputType + Send>: $parent<T> {}

impl<T> IntoIterator for Box<dyn $trait<T>> where T: OutputType {
impl<T> IntoIterator for Box<dyn $trait<T>> where T: OutputType + Send {
type Item = Box<dyn $trait<T>>;
type IntoIter = std::vec::IntoIter<Box<dyn $trait<T>>>;

Expand Down

0 comments on commit 8c34045

Please sign in to comment.