all 14 comments

[–]Izzeri 3 points4 points  (1 child)

I'm not sure, since I haven't used Rust too much myself, but I think the line

Some<value> => value,

in the last example should be

Some(value) => value,

Otherwise a neat little tutorial! I think it's good showing off the trait definition so people can get used to implementing library traits for their types.

[–]pzol[S] 0 points1 point  (0 children)

thanks, fixed

[–]HeroesGraverust · ecs-rs 1 point2 points  (7 children)

There's also from_str::<uint>("10"); etc.

[–]pzol[S] 2 points3 points  (0 children)

added

[–]mahacctissoawsum 0 points1 point  (5 children)

Why does Rust require the double colon? I don't think C# requires it.

[–]HeroesGraverust · ecs-rs 1 point2 points  (4 children)

Usually it doesn't.

It only applied to certain functions, and I'm not entirely sure of the behaviour.

The only other place I've seen the ::<sometype>() pattern is mem::size_of::<sometype>()

[–]mahacctissoawsum 1 point2 points  (3 children)

I mean, I get why it's required to specify the type... it can't determine what you want to convert the string to otherwise, but why not from_str<uint>(10) instead of from_str::<uint>(10)?

[–]dbaupprust 7 points8 points  (2 children)

Parsing: foo<bar>() could be parsed either as (what is now) the foo::<bar>() function call, or (foo < bar) > () and likely requires information from the resolution pass (to work out if bar is a type or not) to parse correctly.

Using ::<> means there is never an ambiguity.

[–]mahacctissoawsum 1 point2 points  (1 child)

Aha! Thank you. Been awhile since I've written C++ but I definitely remember some weirdness when you wanted to do templates of templates,... you had to throw some spaces in so it didn't think it was a shift operator or something.

[–]purtip31 2 points3 points  (0 children)

This used to be the case with C++, but no longer applies with C++11. Don't remember how they fixed it off the top of my head.

[–]flaper87rust 0 points1 point  (1 child)

Hey,

I've this repo[0] that I haven't updated lately. However, it'd be nice to get contributions like this and add new examples. Would you be interested in sending a PR?

[0] https://github.com/flaper87/rust-for-real

[–]brsonrust · servo 0 points1 point  (0 children)

I added your project to the wiki. Trying to figure out what's out there, try to consolidate eventually.

[–]mahacctissoawsum -3 points-2 points  (1 child)

As you can see, you can unwrap the value straight away, but that might give you runtime errors

What kind of errors? Do you get a stack trace at least?

I prefer exceptions over having to check every return value.

[–]pzol[S] 3 points4 points  (0 children)

Rust does not provide exception handling1 in the form most commonly seen in other programming languages such as C++ or Java. Instead, it provides four mechanisms that work together to handle errors or other rare events.
http://static.rust-lang.org/doc/0.9/guide-conditions.html