Skip to content

Commit aa9d210

Browse files
mrchanteyvldm
authored andcommitted
Use example from inline docs in readme
1 parent ff8c6c5 commit aa9d210

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ use std::convert::TryFrom;
2424

2525
use eyre::bail;
2626
use quote::quote;
27-
use rstml::{parse2, node::{Node, NodeAttribute, NodeElement, NodeText}};
27+
use rstml::{
28+
node::{Node, NodeAttribute, NodeElement, NodeText},
29+
parse2,
30+
};
2831

2932
// Create HTML `TokenStream`.
3033
let tokens = quote! { <hello world>"hi"</hello> };
@@ -33,14 +36,20 @@ let tokens = quote! { <hello world>"hi"</hello> };
3336
let nodes = parse2(tokens)?;
3437

3538
// Extract some specific nodes from the tree.
36-
let Node::Element(element) = &nodes[0] else { bail!("element") };
37-
let Node::Attribute(attribute) = &element.attributes[0] else { bail!("attribute") };
38-
let Node::Text(text) = &element.children[0] else { bail!("text") };
39+
let Node::Element(element) = &nodes[0] else {
40+
bail!("element")
41+
};
42+
let NodeAttribute::Attribute(attribute) = &element.attributes()[0] else {
43+
bail!("attribute")
44+
};
45+
let Node::Text(text) = &element.children[0] else {
46+
bail!("text")
47+
};
3948

4049
// Work with the nodes.
41-
assert_eq!(element.name.to_string(), "hello");
50+
assert_eq!(element.name().to_string(), "hello");
4251
assert_eq!(attribute.key.to_string(), "world");
43-
assert_eq!(String::try_from(&text.value)?, "hi");
52+
assert_eq!(text.value_string(), "hi");
4453
```
4554

4655
## Powered by rstml

0 commit comments

Comments
 (0)