Help: the trait `std::marker::Send` is not implemented for `dyn Future>, Error>>`

⚓ rust    📅 2025-05-07    👤 surdeus    👁️ 4      

surdeus

Warning

This post was published 56 days ago. The information described in this article may have changed.

I want to put asynchronous methods into a map and trigger different methods with different keys, but now it prompts me that the returned results cannot be safely passed in the thread. How should I handle this

pub type Result<T, E = error::Error> = std::result::Result<T, E>;

#[derive(thiserror::Error, Debug)]
pub enum Error {

/// Return `404 Not Found`
#[error("request path not found")]
NotFound,

#[error("an error occurred with the database")]
Sqlx(#[from] sqlx::Error),

#[error("an error occurred with the hyper")]
Hyper(#[from] hyper::Error),

#[error("an error occurred with the Protobuf")]
Protobuf(#[from] protobuf::Error),

#[error("std io error")]
Io(#[from] std::io::Error),

}

type Handler = Box<
dyn Fn(Arc, Option<Vec>) -> Pin<Box<dyn Future<Output = Result<Option<Vec>>>>>
+ Send
+ Sync,

;

static HANDLERS_MAP: OnceLock<HashMap<u8, Handler>> = OnceLock::new();

pub async fn accept(uid: Arc, data: Option<Vec>) -> Result<Option<Vec>> {}
pub async fn send(uid: Arc, data: Option<Vec>) -> Result<Option<Vec>> {}

1 post - 1 participant

Read full topic

🏷️ rust_feed