Skip to content
Discussion options

You must be logged in to vote

The most common use case for Data is to create shared state which is why it works this way; it is a safe default.

Alternatives for b):

  • LocalData from actix-web-lab
    • uses an Rc internally
  • .app_data("some state") + req.app_data::<&'static str>() where async fn handler(req: HttpRequest) { ...
    • pro: skips the extra boxed pointers entirely
    • con: potentially requires more boilerplate in handlers

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@bandrefilipe
Comment options

Answer selected by bandrefilipe
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants