4 ms·
I thought it might be useful to document my experiences starting out with Rust, in the same vein as Artyom's "Learning Racket" series (http://artyom.me/learning
by rogual 12y ago
I thought it might be useful to document my experiences starting out with Rust, in the same vein as Artyom's "Learning Racket" series (http://artyom.me/learning-racket-1 http://artyom.me/learning-racket-1), which I got a lot out of.
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.
- th0br0 12y agoI'd strongly recommend using Rust's nightlies. http://www.rust-lang.org/install.html http://www.rust-lang.org/install.html - they've even got pkg installers for Mac.
- rogual 12y agoThanks! I'm on the nightlies now, and things are going a lot more smoothly :)
- sanderjd 12y agoYou 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/ http://caskroom.io/
- bjz_ 12y agoI've been using my own `rustup` script, but this is much nicer!
- sanderjd 12y agoI 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'
- krat0sprakhar 12y agoThanks 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
- rogual 12y agoHey, 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.
- sanderjd 12y agoThis 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 http://is.gd/latFCh. Enjoy!
- bjz_ 12y agoWould you be able to put your `rustc -v` at the top of the page?
- rogual 12y agoGood idea. I switched versions partway through, but I'll list both.
- gwillen 12y agosanderjd: Your comment (sibling of this one) appears to have been moderated. I suspect it's because of your use of is.gd.
- sanderjd 12y agoYeah, 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.