Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ive been making it my mission to improve the docs, especially as the language settles down.

Any suggestions welcome, here or via email.



1) I think I've had 4 different people try to explain lifetimes to me and I still don't think I understand.

2) The use of pointer dereferencing in closures is still quite confusing to me. For example, from the tutorial:

  let square = |x: int| -> uint { (x * x) as uint };
no pointer dereferencing, yet:

  [1, 2, 3].map(|x| if *x > max { max = *x });
uses pointer dereferencing. I can't figure out any rhyme or reason behind it.

3) How do you create traits that can be automatically derived? How do you implement a default method?

4) How do you create and use macros, and in what situations are they the appropriate solution over other forms? (I'm used to using macros in lispy languages, but using them as pervasively in other languages seems to be a form of code smell).


Maybe this will be useful to understanding lifetimes: http://static.rust-lang.org/doc/0.8/tutorial-borrowed-ptr.ht...

As for the pointer dereferencing, perhaps putting the type there will make it clearer:

    [1, 2, 3].map(|x: &int| if *x > max { max = *x });
Now you can see that x isn't actually an int but a reference to one.

As for automatically derived traits, those are actually slightly more powerful macros implemented in the compiler itself. You can see it at rust/src/libsyntax/ext/*.

For default methods, you just put the code you want in the trait itself. Like so:

    trait Animal {
        fn sound(&self) -> ~str;
        fn make_sound(&self) {
            println(self.sound());
        }
    }
The make_sound method is what's called a default method. If you implemented that trait, at the very least you would have to define the sound method and if you wanted to, you could override the default make_sound method.

Macros are actually created with another macro called macro_rules. I'll defer to the tutorial for them: http://static.rust-lang.org/doc/0.8/tutorial-macros.html


> How do you create and use macros, and in what situations are they the appropriate solution over other forms?

I would say to follow a Lisp rule, I like to follow in all languages that have macro support, "only implement a macro if it cannot be done with a function".


I would really love if the reference docs pointed to the underlying code. Many times I'll skim through the reference docs looking for something that I need...then search github for the same section in code so that I can see how it is actually used (or implemented, since the compiler is often the best place to learn Rust itself).

Would be great if the docs just linked straight to the function/crate in github.


This is actually in the "reference" implementation of the current web interface: http://seld.be/rustdoc/master/std/from_str/trait.FromStr.htm... (the [src] link.)

(That feature has yet to be ported to the Rust port of the HTML generator though.)


I think it would be better if it was HTML in the page, github might be down, or you could use it offline (like travelling in a plane, coding).



Wow, you guys are fast :)


Even better: alexcrichto is ridiculously fast, and [src] links will be landing in a few hours (assuming tests pass) in https://github.com/mozilla/rust/pull/9577.

Example: http://www.contrib.andrew.cmu.edu/~acrichto/doc/std/from_str...


Come and join us and be fast!


I'm working on something Rusty https://github.com/DanielFath/xml_parser ;) as my side project. But it's so woefully incomplete I am ashamed of showing it. It's mostly based on

- https://github.com/Florob/RustyXML

- http://fantom.org/doc/xml/index.html

Once that is finished, I might come and help on the Core/Servo. I just don't think I'd be much of a help if I don't use/know Rust/C++ very well.


rust-http was the very first thing that I worked on when I came to Rust, not knowing the language up until then. And it hasn't been turning out too badly.


> And it hasn't been turning out too badly.

Yeah it's been very smooth sailing :) Only pain point was @ pointers in BytesReader interface, but aside from that it's way less bumpy than anticipated.


We generate a PDF of the documentation too.


Here's the issue for adding that capability directly to rustdoc: https://github.com/mozilla/rust/issues/2072


Your book is definitely an excellent contribution (I bought it as soon as I found out about it). When I first came to the language I was a little surprised that O'Reilly didn't have a book out, but I guess it was too unstable even for them. Having a good reference that covers not only the syntax (which isn't that hard to learn, let's be honest) but the best practices and common patterns in the language is always a real help.


Thanks! Yeah, I'm sure O'Reilly would want something out for 1.0, but not before.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: