On Fri, Nov 8, 2013 at 3:43 AM, Gaetan <[email protected]> wrote:

> I agree, I don't understand the syntax here.
>
> Look at the Url class:
>
>
> pub struct Url {
>     scheme: ~str,
>     user: Option<UserInfo>,
>     host: ~str,
>     port: Option<~str>,
>     path: ~str,
>     query: Query,
>     fragment: Option<~str>
> }
>
> pub type Query = ~[(~str, ~str)];
>
> fn split_char_first(s: &str, c: char) -> (~str, ~str) {
>     ...
>     if index+mat == len {
>         return (s.slice(0, index).to_owned(), ~"");
>     }
> }
>
>
> Isn't simpler, and easier to read, if we write it
>
>
> pub struct Url {
>     scheme: str,
>     user: Option<UserInfo>,
>     host: str,
>     port: Option<str>,
>     path: str,
>     query: Query,
>     fragment: Option<str>
> }
>
> pub type Query = [(str, str)];
>
> fn split_char_first(s: &str, c: char) -> (str, str) {
>     ...
>     if index+mat == len {
>         return (s.slice(0, index).to_owned(), "");
>     }
> }
>
>
> KISS !
>

It couldn't be called `str`, because `&str` is a slice.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to