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

Way to List Routings #3086

Closed
Tahinli opened this issue Dec 19, 2024 · 2 comments
Closed

Way to List Routings #3086

Tahinli opened this issue Dec 19, 2024 · 2 comments

Comments

@Tahinli
Copy link

Tahinli commented Dec 19, 2024

  • [ x ] I have looked for existing issues (including closed) about this

Feature Request

Motivation

Hi, I'm building a forum and want to implement dynamic permission system. My plan is every routing will insert themselves in a table with a unique key and I will handle it. Currently I need a way to list all of my routings. I need this kind of thing :

async fn pong() -> impl IntoResponse {
   StatusCode::OK
}
fn main() {
   let router = Router.new().route("/ping", get(pong));
   // I need this kind of thing
   for routing in router {
      assert_eq!((ping, pong), routing);
  }
}

Proposal

You obviously keep all routings to route them. I think you do it with hashmap. So I just need them to be exposed for developers somehow. I don't know if any drawback exists.

Alternatives

  1. I also asked this in rust user forum -> https://users.rust-lang.org/t/list-all-routings/122725
    and a person "parasyte" seems like solving my problem somehow but I think it could be nice if axum gives us a way to list routings since it can also be useful in other scenarios then mine.

  2. I could use https://docs.rs/axum-routes/latest/axum_routes/ to keep all my routings in enum and I can somehow list them but it's another dependency for sure and it's main purpose is surely creating routings with enums with some compile, runtime checking. I think it's a useful crate but in my situation it seems a bit overkill.

@jplatte
Copy link
Member

jplatte commented Dec 19, 2024

Duplicate of #2515. I'm sorry but we are not going to add this. You will have to write your own wrapper of the Router, or find a crate that does something like that. (aide and utoipa do something similar, if you need inspiration)

@jplatte jplatte closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2024
@Tahinli
Copy link
Author

Tahinli commented Dec 19, 2024

Duplicate of #2515. I'm sorry but we are not going to add this. You will have to write your own wrapper of the Router, or find a crate that does something like that. (aide and utoipa do something similar, if you need inspiration)

Sorry for duplication I checked for similar issues but couldn't find it.

Just for curiosity, why you don't want to do it ? Isn't it useful for devs ?

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

2 participants