I have the following semi-minimal reproduction:
async fn process(url: Url) -> Result<()> {
let bytes = fetch(url.clone()).await?;
let page = String::from_utf8(bytes.clone())?;
let page = kuchiki::parse_html().one(page);
//let links = get_links(&page, url);
drop(page);
let links: Vec<Url> = vec![];
for url in &links {
add_url(&url).await.unwrap();
}
Ok(())
}
This gives the following error. What is confusing about this error is that I explicitly drop
page
before the add_url
line, so I'm not sure what the issue is.
error: future cannot be sent between threads safely
--> src/main.rs:321:22
|
321 | let handle = tokio::spawn(async move {
| ^^^^^^^^^^^^ future created by async block is not `Send`
|
::: /home/vedantroy/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.4.0/src/task/spawn.rs:129:21
|
129 | T: Future + Send + 'static,
| ---- required by this bound in `tokio::spawn`
|
= help: within `impl futures::Future`, the trait `std::marker::Send` is not implemented for `Rc<Node>`
note: future is not `Send` as this value is used across an await
--> src/main.rs:264:9
|
256 | let page = kuchiki::parse_html().one(page);
| ---- has type `NodeRef` which is not `Send`
...
264 | add_url(&url).await.unwrap();
| ^^^^^^^^^^^^^^^^^^^ await occurs here, with `page` maybe used later
...
267 | }
| - `page` is later dropped here