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 !
-----
Gaetan
2013/11/8 Jason Fager <[email protected]>
> Can you speak a little to the practical differences between owned boxes
> and ~[T]/~str? How does the difference affect how I should use each?
>
>
> On Thursday, November 7, 2013, Daniel Micay wrote:
>
>> On Thu, Nov 7, 2013 at 6:32 PM, Liigo Zhuang <[email protected]> wrote:
>>
>>> > Owned boxes shouldn't be commonly used. There's close to no reason to
>>> use one for anything but a recursive data structure or in rare cases for an
>>> owned trait object.
>>> >
>>> > http://static.rust-lang.org/doc/master/tutorial.html#boxes
>>> >
>>> > It's important to note that ~[T] and ~str are not owned boxes. They're
>>> just sugar for dynamic arrays, and are common containers.
>>> >
>>> It's so confusing. If it's not owned box, why not remove ~? Make "str"
>>> default be dynamic should OK.
>>>
>>
>> It wouldn't be okay for every string literal to result in a heap
>> allocation.
>>
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev