-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Rama web router #423
Rama web router #423
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.
Please make use of matchit
and adapt the code accordingly.
let uri_string = req.uri().to_string(); | ||
match &self.routes.at(uri_string.as_str()) { | ||
Ok(matched) => { | ||
let params: HashMap<String, String> = matched.params.clone().iter().map(|(k, v)| (k.to_string(), v.to_string())).collect(); |
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.
This will need to be collected as https://docs.rs/rama/latest/rama/http/matcher/struct.UriParams.html to be compatible with the existing matcher object. Feel free to expand the logic of UriParams if you miss something.
E.g. might make code cleaner here if you implement FromIterator
for UriParams
, but that's more of an optional thing.
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.
Also in general there should be no reason to double allocate.
- first allocation is .clone()
- than you allocate again by turning the pairs into owned pairs
Probably that first clone isn't needed
@@ -100,7 +49,125 @@ where | |||
/// create a new web router | |||
pub(crate) fn new() -> Self { | |||
Self { | |||
routes: TrieNode::new(), | |||
routes: MatchitRouter::new(), | |||
not_found: Arc::new( |
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.
this can probably be made optional so you don't need to assign it if not set, and instead just fallback to NOT_FOUND anyway but on the spot
pub struct Router<State> { | ||
routes: TrieNode<State> | ||
routes: MatchitRouter<HashMap<Method, Arc<BoxService<State, Request, Response, Infallible>>>>, |
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.
We also need to be able to nest and merge btw, so I think this approach is a bit too simplistic
Closed as this isn't the desired approach and won't be continued as communicated off channel. |
Fixes #396