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

Non-'static lifetime for non-root contexts #191

Open
haikuginger opened this issue Mar 20, 2023 · 0 comments
Open

Non-'static lifetime for non-root contexts #191

haikuginger opened this issue Mar 20, 2023 · 0 comments

Comments

@haikuginger
Copy link

Hi all!

Currently, because create_http_context and similar return non-lifetimed traits, my implementation of HttpContext has to have a 'static lifetime; all the data it contains has to be valid for the entire life of the program. Which is reasonable.

However, my root parses a bunch of data and configuration and holds onto it. To make that data available inside my HttpContext implementation, I can either copy the entirety of that data into the context, or I can make a reference-counted container that gets cloned into the context.

Obviously, one of those options is better than the other, but I was wondering if it's reasonable to say that a request context will never outlive the root context it originated from. If so, then it would be great to update the RootContext trait to have a lifetime parameter 'a, and require it to return only subcontexts that also have lifetime 'a. That would allow HTTP or stream contexts to have simple non-mutable references to the root context. My understanding is that this should also be backwards-compatible, because all current implementations should return 'static contexts which last strictly longer than any other lifetime 'a.

@haikuginger haikuginger changed the title Non 'static lifetime for non-root contexts Non-'static lifetime for non-root contexts Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant