Replies: 1 comment 3 replies
-
actix-web uses use std::rc::Rc;
use actix_web::{App, HttpServer};
fn main() {
let rc = Rc::new(123);
HttpServer::new(move || {
let _ = rc.clone(); // this would not work.
let rc = Rc::new(123); // this would.
App::new()
});
}
use std::sync::Mutex;
use actix_web::{App, HttpServer};
fn main() {
HttpServer::new(|| {
App::new()
.app_data(ptr())// !Send + !Sync
.app_data(Mutex::new(())) // !Clone + !Copy
});
}
fn ptr() -> *mut String {
todo!()
} In other word |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Why does
HttpServer
take a App factory and calls the very same closure on each worker thread? I am trying to understand this design, as one could very well instantiate oneApp
struct and thenClone
it across the various worker threads. Sinceapp_data
requires all data to beCopy
,Clone
,Send
,Sync
, I was under the impression thatApp
could be cloned and sent across threads as well.Is it because the
vec
s in here have something that aren'tClone
able orSend
able?Beta Was this translation helpful? Give feedback.
All reactions