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
🏷️ rust_feed