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

Make Router generic over its route 🚏 #240

Merged
merged 1 commit into from
Jul 30, 2021
Merged

Commits on Jul 25, 2021

  1. Make Router generic over its route 🚏

    Our `Router` and `RouteHandler` infrastructure was designed to work
    with plain `URL`'s on its main APIs. Despite URLs being the critical
    piece of information to route (e.g. in our `TrieRouter`), in certain
    situations the URL doesn't contain all the information, which limits
    the Routing infrastructure capabilities. One such example would be in
    a server middleware router, where the HTTP method would likely be
    required information to pass on to handlers to perform adequate routing.
    
    To remove this restriction, a new `Routable` protocol was created to
    represent a routable type, which only needs to provide a `url` and is
    forwarded by the router to the handler upon a successful match. To make
    it easier to unpack any additional information on the handlers and have
    more type safety, it was made an `associatedtype` of both `Router` and
    `RouteHandler`, effectively turning it into a new generic `R`.
    
    ## Changes
    
    - Add new `Routable` protocol, add default conformance to `URL`.
    
    - Add new `associatedtype R: Routable` to `Router` and `RouteHandler`.
    
    - Update `Router` and `RouterHandler` APIs to receive a route of type
    `R`.
    
    - Add new `RouteHandler.eraseToAnyRouteHandler` helper.
    p4checo committed Jul 25, 2021
    Configuration menu
    Copy the full SHA
    120be87 View commit details
    Browse the repository at this point in the history