3 ms·
I understand the frustration while learning Rust. As a Rust beginner myself, I suggest not to follow guides (except the ones at http://www.rust-lang.org http://
by kaoD 12y ago
I understand the frustration while learning Rust. As a Rust beginner myself, I suggest not to follow guides (except the ones at http://www.rust-lang.org http://www.rust-lang.org) since most are outdated.
My way to learn Rust: I spend 90% of the time in Rust's std docs, 9% of the time watching the type/borrow checker spit at me and 1% of the time in IRC when I'm out of ideas. Google was useless most of the time.
I found revisiting http://doc.rust-lang.org/index.html http://doc.rust-lang.org/index.html (specially the spec and the first four guides) as I was getting insights from experimenting with the language allowed to me to understand what was going on.
For me the most important parts to understand to get up to speed were:
- The module system (understanding `mod` vs. `use`).
- The concept of ownership. References. Lifetimes. Borrows. Copies. Moves. Moving out of. `ref` on tuples.
- Getting used to rustdoc's format. Docs hard to navigate not knowing the language idiosyncrasies. Trait methods are often not textually documented.
- Understanding rustc error reporting. IMHO the worst part of rustc is the cryptic lifetime error messages (though they're getting better).
Good luck in your journey! I'm loving Rust so far.
---
Some concrete feedback:
> This probably isn't right (I'm sure empty maps must be supported somehow), but it will do for now.
Indeed. I see you joined the IRC (great idea, people are very helpful there) and got the correct syntax, but to fix the ~str problem, the answer is:
let mut map = HashMap::<Box<str>, uint>::new();
Box<A> is the resulting type of an expression "box a" where `a` is of type A. I guess an example will make it more clear:
let owned_three: Box<uint> = box 3;
But Box<str> is actually just String, so the final line should read:
let mut map = HashMap::<String, uint>::new();
By the way... why do you need to box the str?
Local bindings (args, let bindings...) are allocated on the stack and must have a fixed size. A string has variable size by definition, but a box has a known size (the size of a reference to your heap-allocated str), so can can wrap the str (on the heap) on a box (on the stack).
That's why you'll never see a sole `str` as a type: you either see the (boxed) String or &str (reference to a string slice).
> Ah, OK. So I think this means Rust has no built-in way of determining if two int-arrays are equal.
Actually the problem is Rust currently doesn't implement traits for static-sized arrays because the size is part of the type signature and each size would need to be implemented separately.
https://github.com/rust-lang/rust/issues/7622 https://github.com/rust-lang/rust/issues/7622
Though the Coord solution you implemented is in my opinion better for a typed language.
- pcwalton 12y ago> Actually the problem is Rust currently doesn't implement traits for static-sized arrays because the size is part of the type signature and each size would need to be implemented separately. But it does implement those traits for slices. So this isn't typically a problem in practice because you can coerce fixed-length arrays to slices and then compare those.
- kaoD 12y agoIndeed, though it's still a pain for nested arrays, as you have to coerce the inner layers first via mapping. Quite burdensome for arbitrary nesting. Anyways, most of the time you're better off implementing a concrete type like he did.
- lostdog 12y ago> As a Rust beginner myself, I suggest not to follow guides (except the ones at http://www.rust-lang.org http://www.rust-lang.org) since most are outdated. Nearly every (external) guide I've tried to use is out of date, but it's impossible to tell from the guide itself. I wish everyone who wrote a guide or tutorial would label it with the version of Rust it works with (or at least the date).
- bjz_ 12y agoYeah, we highly recommend blog post authors to put their `rustc -v` at the top of the page, at least until 1.0 (which is not far off).