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

Context trait design clashes with borrow checker #303

Open
miwig opened this issue Feb 12, 2025 · 0 comments
Open

Context trait design clashes with borrow checker #303

miwig opened this issue Feb 12, 2025 · 0 comments

Comments

@miwig
Copy link

miwig commented Feb 12, 2025

The design of the context traits in src/traits.rs seems to mimic a C++-style inheritance based design by providing default implementations of trait functions, but this prevents certain code patterns from working because of the borrow checker, e.g. iterating mutably over a struct field while calling self.dispatch_http_call and storing the returned token in the field. Because dispatch_http_call takes my context struct as a &self parameter, I can not call it while having a field of my struct mutably borrowed, as is the case when iterating mutably.

Note that none of these default implementations actually access the self parameter, they all just call something from the hostcalls module. It also seems like it doesn't make much sense to override most of them, except the ones that the host calls for us.

The proxy-sdk crate seems to have found a design that meshes better with the way things work in Rust. (I am not affiliated with them and haven't tried it out yet.)

miwig added a commit to antonengelhardt/wasm-oidc-plugin that referenced this issue Feb 12, 2025
Simplify discovery.rs a bit by removing some mutexes that are not strictly necessary.
We do however need to work around proxy-wasm/proxy-wasm-rust-sdk#303
by using the hostcalls module (around which the HttpContext trait is just a trivial wrapper) directly
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