proxy-wasm-rust-sdk icon indicating copy to clipboard operation
proxy-wasm-rust-sdk copied to clipboard

Non-'static lifetime for non-root contexts

Open haikuginger opened this issue 2 years ago • 0 comments

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 avatar Mar 20 '23 22:03 haikuginger