News for hackers. Stuff that matters.
Re:Learning Rust by rogual on Sunday November 02, 2014 @08:45AM (#8546562)
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), 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.

Re:Learning Rust by sanderjd on Sunday November 02, 2014 @08:29PM (#8548918)
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!
Re:Learning Rust by th0br0 on Sunday November 02, 2014 @10:00AM (#8546722)
I'd strongly recommend using Rust's nightlies. http://www.rust-lang.org/install.html - they've even got pkg installers for Mac.
Re:Learning Rust by sanderjd on Sunday November 02, 2014 @08:04PM (#8548862)
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/

Re:Learning Rust by bjz_ on Sunday November 02, 2014 @09:26PM (#8549054)
I've been using my own `rustup` script, but this is much nicer!
Re:Learning Rust by sanderjd on Monday November 03, 2014 @09:47AM (#8550980)
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'
Re:Learning Rust by rogual on Sunday November 02, 2014 @10:19AM (#8546784)
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

Re:Learning Rust by rogual on Sunday November 02, 2014 @11:36AM (#8547018)
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.

Re:Learning Rust by bjz_ on Sunday November 02, 2014 @09:40PM (#8549091)
Would you be able to put your `rustc -v` at the top of the page?
Re:Learning Rust by rogual on Monday November 03, 2014 @09:05AM (#8550780)
Good idea. I switched versions partway through, but I'll list both.
Re:Learning Rust by gwillen on Monday November 03, 2014 @01:59AM (#8549676)
sanderjd: Your comment (sibling of this one) appears to have been moderated. I suspect it's because of your use of is.gd.
Re:Learning Rust by sanderjd on Monday November 03, 2014 @09:50AM (#8550995)
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.