I was playing around with this library, which looks super cool. I'm excited to be able to have more validation in HTML. I was trying to compose a couple different chunks of HTML in the following manner:
#![feature(proc_macro_hygiene)]
extern crate typed_html;
use typed_html::dom::DOMTree;
use typed_html::html;
fn outer(body: DOMTree<String>) -> DOMTree<String> {
html!(
<html>
<head>
<title>"Sample Title"</title>
</head>
<body>
{ body }
</body>
</html>
)
}
fn index() -> DOMTree<String> {
outer(html!(
<div>
<h1>"Test"</h1>
<p>"A test of things"</p>
</div>
))
}
fn main() {
println!("{}", index().to_string());
}
But it seems like DOMTree doesn't implement IntoIterator properly to compose these, even though it seems like it should given that you can nest html!() calls. This is the error I get:
error[E0599]: no method named `into_iter` found for type `std::boxed::Box<dyn typed_html::dom::Node<std::string::String>>` in the current scope
--> examples/test.rs:8:5
|
8 | / html!(
9 | | <html>
10 | | <head>
11 | | <title>"Sample Title"</title>
... |
16 | | </html>
17 | | )
| |_____^
|
= note: the method `into_iter` exists but the following trait bounds were not satisfied:
`std::boxed::Box<dyn typed_html::dom::Node<std::string::String>> : std::iter::IntoIterator`
`&std::boxed::Box<dyn typed_html::dom::Node<std::string::String>> : std::iter::IntoIterator`
`&mut std::boxed::Box<dyn typed_html::dom::Node<std::string::String>> : std::iter::IntoIterator`
`dyn typed_html::dom::Node<std::string::String> : std::iter::IntoIterator`
`&dyn typed_html::dom::Node<std::string::String> : std::iter::IntoIterator`
`&mut dyn typed_html::dom::Node<std::string::String> : std::iter::IntoIterator`
I also tried to wrap it into vec![body].into_iterator(), giving a slightly different error:
error[E0308]: mismatched types
--> examples/test.rs:8:5
|
8 | / html!(
9 | | <html>
10 | | <head>
11 | | <title>"Sample Title"</title>
... |
16 | | </html>
17 | | )
| |_____^ expected trait `typed_html::elements::FlowContent`, found trait `typed_html::dom::Node`
|
= note: expected type `std::boxed::Box<(dyn typed_html::elements::FlowContent<_> + 'static)>`
found type `std::boxed::Box<dyn typed_html::dom::Node<std::string::String>>`
Is this something that is expected to work? Am I doing something wrong? Or is there some other way I should go about this sort of thing?
I was playing around with this library, which looks super cool. I'm excited to be able to have more validation in HTML. I was trying to compose a couple different chunks of HTML in the following manner:
But it seems like DOMTree doesn't implement IntoIterator properly to compose these, even though it seems like it should given that you can nest
html!()calls. This is the error I get:I also tried to wrap it into
vec![body].into_iterator(), giving a slightly different error:Is this something that is expected to work? Am I doing something wrong? Or is there some other way I should go about this sort of thing?