-
-
Notifications
You must be signed in to change notification settings - Fork 18
chore: allow empty str #25
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
Conversation
cc #26 |
@adriangb In this case: Router(
{
"/users": Router(
{
"": users_endpoint,
"/:name": user_endpoint,
}
)
) Can the sub-router get the prefix path |
Not easily. That same instance could be used somewhere else as well. |
I'm realizing I may have misunderstood. Just to clarify, I don't think the nested router should know/need to know that it is mounted under the prefix With the example you gave I think the routing should be as follows:
|
In writing, empty string can be used, but a full path can be assembled at the end. Pseudo codes:
|
Yeah that’s one way to do it. It’s nice to be able to support the version where the parent router doesn’t need to introspect into itself children |
a1f13c5
to
1fc018c
Compare
tree.insert("", 14); | ||
let r = tree.find("/").unwrap(); | ||
assert_eq!(r.value, &14); |
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 is a bit confusing. The path goes in as "/"
but comes out as "/"
?
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.
tree.insert("", 14)
allow change the start node value , but it does not modify the node prefix path.
tree.insert("", 14)
node path = ''tree.insert("/", 15)
node path = '/', overwrite the empty string
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.
Or do not allow empty string, users handle their own paths
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.
here is another way to allow ''
to be the root node of the tree and '/'
to be its child node. (@adriangb This should be what you expect).
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.
Yea I would expect “/“
to be a child of ””
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.
Because, I always consider that the real request path does not appear ''
, when organizing the routing system, it has to pre-process path at the users
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.
For what it's worth I was easily able to work around this one level of abstraction up: adriangb/routrie@70fc7c5
I think the fact that this can be solved one level of abstraction up indicates that the limitation is artificial/due to the implementation, not a conceptual one.
#19
@adriangb try this branch