With crate Curl, I want to write received data in String.
I do this, Result data
of write_function(..) is &[u8]
let html: String = String::new(); let mut easy = Easy::new(); easy.write_function(|data| { html = String::from_utf8(Vec::from(data)).unwrap(); Ok(data.len()) }).unwrap();
I have this error
Compiling htmlparser v0.0.1 (file:///C:/Users/RUST%20Project/htmlparser)
src\main.rs:37:25: 37:31 error: closure may outlive the current function, but it borrowshtml
, which is owned by the current function [E0373]
src\main.rs:37 easy.write_function(|data| {
^~~~~~
src\main.rs:37:25: 37:31 help: runrustc --explain E0373
to see a detailed explanation
src\main.rs:38:9: 38:13 note:html
is borrowed here
src\main.rs:38 html = String::from_utf8(Vec::from(data)).unwrap();
^~~~
src\main.rs:37:25: 37:31 help: to force the closure to take ownership ofhtml
(and any other referenced variables), use themove
keyword, as shown:
src\main.rs: easy.write_function(move |data| {
But I can't do move |data|
, String does not implement the Copy
trait.
How can I write received data into String?