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
HttpServertake 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 oneAppstruct and thenCloneit across the various worker threads. Sinceapp_datarequires all data to beCopy,Clone,Send,Sync, I was under the impression thatAppcould be cloned and sent across threads as well.Is it because the
vecs in here have something that aren'tCloneable orSendable?Beta Was this translation helpful? Give feedback.
All reactions