-
Notifications
You must be signed in to change notification settings - Fork 155
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
Url/Router - new API design #383
Comments
What do you think about giving an iterator instead of custom methods? match url.next_path_part() {
None => Page::Home,
Some("report") => Page::Report(page::report::init(url)),
_ => Page::Unknown(url),
} something like match url.into_path_iter().next() {
None => Page::Home,
Some("report") => Page::Report(page::report::init(url)),
_ => Page::Unknown(url),
} I used to match segments {
[""] => Screen::Home,
["about"] => Screen::About,
["profile"] => Screen::Profile,
["signin"] => Screen::SignIn,
["signup"] => Screen::SignUp,
... UPD. found |
👍 what about url.path().iter().next() or url.path().into_iter().next() Instead of
|
@flosse : I've implemented custom methods because I'm not able to come with clean API that integrates |
For our work project I'm using very simple approach: there is a simple I checked
If I'd try to imagine how it should be then: /// Derive `From<Url>`, `Into<Url>` and `Display`.
#[derive(Router)]
enum Page {
#[route("/")]
Home,
#[route("/user/profile")]
Profile,
#[route("/posts")]
Posts,
}
fn view() {
a![ attrs!{ At::Href => Page::Home } ]
} |
@TatriX How should I use it ^ with nested modules? Let's assume we have sitemap like:
And all pages have own
|
Yes, unfortunately I can't show it. I haven't thought that much about nested modules, but I would just mod user {
pub enum Page {}
fn view() {
a![href => crate::admin::Page::Reports],
}
}
mod admin {
enum Page {
Reports,
}
}
So yes, one Page/Router per module.
That's also something I need to find out at some point in future, but my first thought was to use approach similar to /// Return `cane/hour` data for plotting.
#[get("/stats?<from>&<to>")]
pub fn get_stats(
conn: db::Conn,
from: String,
to: String,
_auth: Auth,
) -> Vec<Foo> {
} Maybe something like this can be used to embed various params as well: enum Page {
Report{
from: String,
to: String,
}
}
fn view() {
a![ href => Page::Report{ from: todo!(), to: todo!() }]
} |
And yet another thing: I was slightly confused about My mental model works like this: you have let absolute = Url::new("https://google.com");
let relative = Url::new("/admin"); Something akin to Then there is logical pages/screens or routing. I like to think of pages being independent from urls, but there should be one to one correspondence between them. So, |
@TatriX I see you have multiple ideas, but nothing proven/complete yet - so I suggest to release And when you find out that it's limiting for you I would be happy to discuss your more-complete alternative for it (probably ideal would be rewritten Some other notes:
|
Hello guys. I am working on the routing and I am on the way to start a PR. Here are the ideas I have in my code for now and I will use some of the suggestion we have in the discussion :
There are few challenges I am having :
This is work in progress, so I need all your inputs. Everybody is welcomed to help on it 😄 My objective is to have an easy way to declare routes and generated the code for it. |
Motivation
1.42.0
).Url
- e.g. domain or protocol.Url
to services/APIs likefetch
.Inspiration
The text was updated successfully, but these errors were encountered: