This is neat. I really admire the willingness to document the type of stumbling around that characterizes lots of real programming, but which you rarely see.
I think it's a bummer you can't do `LevelMap::new()` like you want, but here are two things that work that I think are improvements on your `mklevel` function:
fn mklevel() -> LevelMap { HashMap::new() }
That works because once the compiler knows that the return type is `LevelMap`, which it knows is really `HashMap<Coord, int>`, it can infer which variant of `HashMap::new` to call. Using this same idea, you can get closer to what you originally wanted without the function, like this: let mut map: LevelMap = HashMap::new();
There are also a couple things that I think are good syntactic improvements over the `Coord{x: 0, y: 0}` syntax that you made the `xy` function to avoid. First, you can just use a tuple: type LevelMapTuple = HashMap<(int, int), int>;
let mut maptuple: LevelMapTuple = HashMap::new();
maptuple.insert((0, 0), 0);
If you still want to give it a name, which I think is pretty nice, you can use a struct with anonymous members, like this: struct Coord(int, int);
let mut map: LevelMap = HashMap::new();
map.insert(Coord(0, 0), 0);
Here's a rust playpen link illustrating some of these things: http://is.gd/latFCh. Enjoy!I'd strongly recommend using Rust's nightlies.
http://www.rust-lang.org/install.html - they've even got pkg installers for Mac.
You can also get the rust and cargo nightlies using homebrew-cask[0], which I find a bit easier (though I'm not exactly sure why).
[0]: http://caskroom.io/
I've been using my own `rustup` script, but this is much nicer!
I actually use it with a `rustup` alias, because homebrew-cask isn't great at upgrading nightlies:
alias rustup='brew cask fetch --force rust cargo && brew cask install --force rust cargo && git -C ~/.vim/bundle/rust.vim pull'Thanks! I'm on the nightlies now, and things are going a lot more smoothly :)
Re:Learning Rust
by krat0sprakhar on Sunday November 02, 2014 @11:27AM
(#8546984)
Thanks a lot for sharing this. Its going to be a lot of fun to follow. Sorry to throw feature requests at you but it would be great if you could add email subscription for this series. Also, although I'm a big fan of plain-text, I believe that serving .txt files might not be best for readability.
If your blog / series is on github, I'd happily send PRs for above. Let me know :)
Thanks a lot!
Edit: If you prefer staying away from styling your blog then even writing the content in Markdown would do the trick
Hey, thanks for reading. I agree that I definitely need to improve the presentation — plain-text is a stopgap, really, so I could get something up there before I talked myself out of the whole thing :)
I'm not a regular writer and don't have a blog, so it's not as easy as hitting 'new post' but I'll be sure to get something a bit more usable up soon.
Edit: Converted to Markdown-generated HTML for now.
Would you be able to put your `rustc -v` at the top of the page?
Good idea. I switched versions partway through, but I'll list both.
sanderjd: Your comment (sibling of this one) appears to have been moderated. I suspect it's because of your use of is.gd.
Yeah, that has happened before - it's too bad because is.gd is just the shortener that play.rust-lang.org has built in. I suppose I could use a different shortener myself, but I suspect they are all similarly problematic.
I really liked the style of that series when investigating Racket myself. That is, little to no preparation, and writing down everything you try, even if it doesn't work.
Hope someone finds it useful.