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

Pluggable routing #2792

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

the10thWiz
Copy link
Collaborator

Implements pluggable routing, based on #2790. There are still a number of open questions, and this isn't a final implementation.

TODO:

  • Trait finalization
    • Sync vs Async
    • Implicit ranking
  • AsAny and DynClone
  • Implement some kind of Accepts property, if possible
  • Symmetry
  • Open up to external implementation
  • Update code generation to use new API

Async trait

I think it's worth restricting this to be a synchronous trait. It simplifies the API, and I don't think making the trait async would enable many new options.

Implicit ranking

We can adjust the collides method, to output the following enum:

pub enum CollisionType {
   /// This property ensures that there is no request that matches both routes
   NoCollision,
   /// This property allows two routes to match the same request, but
   /// Rocket should always try this route first.
   SelfFirst,
   /// This property allows two routes to match the same request, but
   /// Rocket should always try the other route first.
   OtherFirst,
   /// This property allows two routes to match the same request
   Collision,
}

AsAny and DynClone

These are blanket implemented traits that solve some minor problems. AsAny is a polyfill for trait upcasting, enabling a trait object of type dyn UniqueProperty to be upcast to dyn Any. DynClone implements Clone on Box<dyn UniqueProperty>. The AsAny polyfill can be removed with some unsafe code (basically a copy-paste of stdlib's downcast_ref). The DynClone can be removed if we use Arc<dyn UniqueProperty>, since it handles clone for us.

Symmetry

Currently, we place the burden on the implementor to ensure that the property is symmetrical (i.e., iff A collides with B, then B collides with A). Since this is only checked once, we could check both sides, and warn or error if they disagree.

@the10thWiz the10thWiz mentioned this pull request May 17, 2024
2 tasks
Also updates codegen, router, and tests to use the new API
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

Successfully merging this pull request may close these issues.

1 participant