feature: add get_route_paths
to path_router
#3127
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added a
get_route_paths
method to thepath_router
to return aVec
of the current paths associated with a router.Motivation
There was a desire to create this feature to support logging frameworks that base their logging off the raw path rather than the path at time of request. I specifically am working on building a client for Apitally in Rust and wanted to support the Axum framework first. I will now be able to supply a list of the applications paths to Apitally. I can see a future where other frameworks desire this functionality as well!
Solution
The paths are already stored in the
path_to_route_id
of thepath_router
. TheRouteId
is not strictly useful in this scenario and is also private. This implementation grabs the keys ofpath_to_route_id
and collects them into aVec
.