Error I got:
future cannot be sent between threads safely
within `tendril::tendril::NonAtomic`, the trait `Sync` is not implemented for `Cell<usize>`
required for the cast from `impl std::future::Future<Output = ()>` to the object type `dyn std::future::Future<Output = ()> + std::marker::Send`
Code where error is thrown
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
onmessage(&ctx, &msg).await;
}
}
function used:
pub async fn onmessage(ctx: &Context, msg: &Message){
let letterboxlink;
let document;
let imdb_link = if msg.content.starts_with(&"https://letterboxd.com/") {
let response = reqwest::get(&msg.content).await.unwrap();
letterboxlink = if response.status().is_success() {
let body = response.text().await.unwrap();
document = scraper::Html::parse_document(&body);
let selector = scraper::Selector::parse(r#"a[data-track-action="IMDb"]"#).unwrap();
document
.select(&selector)
.map(|x| x.value().attr("href"))
.next()
.unwrap()
.unwrap()
} else {
&msg.content
};
letterboxlink
} else {
&msg.content
};
if msg.content.contains(&"imdb.com") {
imdb(ctx, msg, imdb_link).await;
}
}
Hello. I'm having a problem with asynchronous Rust.
I don't really even understand what's going on 😅
I tried Internet, but it didn't really helped me to fix or understand my problem