Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share state using generate context #100

Closed
allevo opened this issue Mar 20, 2019 · 2 comments
Closed

Share state using generate context #100

allevo opened this issue Mar 20, 2019 · 2 comments

Comments

@allevo
Copy link
Contributor

allevo commented Mar 20, 2019

Hi!
I would like to share a state between requests storing it into request context.

The proposal is to create a new trait that implements a method generate

pub trait ContextGenerator {
    fn generate(req: R) -> T;
}

The change is about

@trezm
Copy link
Collaborator

trezm commented Mar 22, 2019

I think this is a great suggestion. In order to maintain backcompat, perhaps it makes sense to alter this method:

https://github.com/trezm/Thruster/blob/master/src/app.rs#L100

And create a new one along side along the lines of

  pub fn build(generator: ContextGenerator<R, T>) -> App<R, T> {
    App {
      _route_parser: RouteParser::new(),
      context_generator: generator // Note that internally we can update this to be a ContextGenerator
    }
  }

@trezm
Copy link
Collaborator

trezm commented Apr 20, 2020

All set!

@trezm trezm closed this as completed Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants