-
Notifications
You must be signed in to change notification settings - Fork 78
refactor: use foreign-type for request #211
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the Request
struct to use the foreign_types::ForeignTypeRef
trait instead of direct wrapper implementation. This change allows the Request
object to avoid unnecessary copying of original ngx_http_request_t
data by using a reference-based approach.
Key changes:
- Replace direct struct wrapping with
ForeignTypeRef
trait implementation - Update all macro call sites to use
ForeignTypeRef::from_ptr_mut()
instead of custom conversion - Add
foreign-types
dependency to enable the new pattern
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/http/request.rs | Refactored Request struct to implement ForeignTypeRef trait and updated all field access to use helper methods |
src/http/upstream.rs | Updated macro to use ForeignTypeRef::from_ptr_mut() for request conversion |
src/core/mod.rs | Added re-export of ForeignTypeRef trait |
examples/upstream.rs | Updated example to use new ForeignTypeRef pattern and added import |
examples/async.rs | Updated async example to use ForeignTypeRef conversion methods |
Cargo.toml | Added foreign-types dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that Request(ngx_http_request_t)
was the wrong representation. I was going to propose that we make it Request(NonNull<ngx_http_request_t>)
with a constructor fn from_http_request(NonNull<ngx_http_request_t>) -> Self
and not use any &mut self
methods, because nginx does not consider any *mut ngx_http_request_t
to be unique, and the uniqueness property of Request does not make its use any more or less unsafe.
f023297
to
82b683d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
82b683d
to
bdce0b4
Compare
Proposed changes
foreign_type::ForeignTypeRef
trait is used to defineRequest
object. While generally the use of this object almost unchanged, reference trait allows to avoid unnecessary copying of originalngx_http_request_t
data.Checklist
Before creating a PR, run through this checklist and mark each as complete.