Hi! I'm trying to use kuchikiki to parse and replace text nodes in html fragments, but I keep getting this error;
error[E0515]: cannot return reference to temporary value
--> src\main.rs:27:71
|
27 | text_node = NodeDataRef::new(text_node.as_node().clone(), |_| &RefCell::new(new_text[index].clone()));
| ^-------------------------------------
| ||
| |temporary value created here
| returns a reference to data owned by the current function
Here's a reproducible example:
let html = "<p>woo<em>hoo</em></p>";
let document = kuchikiki::parse_html().one(html);
let text_list = vec!["hoo".to_string(), "woo".to_string()];
for (index, mut text_node) in document.select("p").unwrap().next().expect("").as_node().descendants().text_nodes().enumerate() {
text_node = NodeDataRef::new(text_node.as_node().clone(), |_| &RefCell::new(text_list[index].clone()));
println!("{:?}", text_node);
}
I can't find any solution that works, so any help will be appreciated. Thanks!