Taking suggestions for the new Rust FAQ!


#22

This is something that bothers me too, perhaps something for the Let’s Talk about Ecosystem Documentation thread. The documentation created through cargo doc does not mention which version of the crate is being documented. The problem seems to be that afaik the documentation is build by rustc but only cargo knows about the version of a crate. Can we mend this somehow?


#23

We already have an issue open about it.


#24

@mbrubeck Wow nice list! Thanks.


#25

More generally, stackoverflow’s Hottest ‘rust’ Answers can perhaps provide some inspiration for the new FAQ, plus other tags such as rust-cargo, rustdoc and questions ordered by votes, e.g. for tag rust.

Makes me wonder whether it’s worth putting in the effort to maintain a large body of programming detail questions and answers in the FAQ. Perhaps pointing developers at the ‘most upvoted questions’/‘hottest answers’ for various rust tags in stackoverflow would make keeping this part comprehensive and current a non-issue?

Interestingly, there is also a rust-faq tag on stackoverflow that currently has only one question listed.


#26

Specific things that have bitten me:

  • Storing Trait objects in a struct gives me a confusing Sized error (Box ?)
  • Use of moved value in match statement on an enum (solution Enum::Value(ref v))
  • Same on use of map on Option (solution: as_ref()
  • Can’t find method implemented as Trait even though Trait is in package already use'd
  • What crate do I use for JSON?
  • &str, &'a str, &'static str, String: Gaack

Higher level:

  • I’m an object oriented programmer. How do I map my OO concepts onto Rust?

#27

What’s the difference between a function and a closure that doesn’t enclose any variable?

(E.g. is the following

v.map(|x| 2 * x);

equivalent to (assuming appropriate types):

fn double (x: i32) -> i32 {
   2 * x
}
v.map(double);

?)


#28

When I first learned about Rust’s safety features, I found not-checking array bounds at compile time strange (at least, by what I expected Rust had at that point). It was confusing and there wasn’t any simple answer to be found. Therefore, I suggest the question:

I have seen this question answered on Stack Overflow. And it maybe a silly thing to ask even.

  • Why array bounds are not checked at compile time?

Edit: Rearranged the structure to avoid giving the impression I’m talking about the previous post in the thread.


#29

Why array bounds are not checked at compile time?

Doing so in general is equivalent to solving the halting problem, since array indices can be produced by arbitrary computations.


#30

I came from Python. What is:

  • moving
  • an Enum
  • a Struct
  • a Trait

Is there a virtual env for multiple rustc installation?

I’m begining a new project, which version should I use? [1.0, stable, beta, nightly?]

Is there coding style, good practices? [http://aturon.github.io/]

I’d like to organize an event, where is the Code of Conduct?

What I can’t do with Rust, right now or in theory?


#31

Just had a discussion on this with the folks. Deref/non-deref coersions were a major blocker for me.


#32

I found the lifetimes section of the Rust book to be a little confusing. Seems to me like more info on lifetimes related to functions would be nice.

Otherwise, something that would be really nice would be something info on Rust related to security. Maybe how often bugs in C++ code, that Rust fixes with borrow checker system cause problems, maybe examples of famous bugs Rust would have fixed… maybe related to threading too. Or maybe a general, how to write secure code article including ways to avoid common mistakes that even Rust can’t catch?

Something else that would be a really nice thing would be a tutorial for learning that assumes no prior knowledge of coding. Would be really nice of beginners could start in Rust… currently most documentation is aimed at converting C programmers it seems.


#33

These are all good points, but I don’t know how much of all that could be reasonably covered in the FAQ. A lot of it sounds like stuff that could be suggested for the Rust book. Maybe @steveklabnik has some thoughts.


#34

Yeah, this seems like “more than FAQ” material to me.

I agree! It’d be very, very hard to write though.


#35

Why would anyone think it’s a good idea to teach Rust to coding beginners?


#36

There are a number of places that currently teach C or C++ as a first language to new programmers. If a person is going to start out with a programming language that exposes low-level constructs, wouldn’t it be best to start out with a low-level language that encourages and enforces safety?

Regardless of whether choosing Rust is the absolute best option for a first-language (and I seriously doubt that any best option exists), we should expect that some people will eventually begin coming to Rust as their first language. Don’t we want to be accomodating when that happens?


#37

I feel sorry for those that get taught C or C++ as first language. An example of a more suitable one is Python. But, since it’s inevitable, then it should be Rust before it’s C/C++.


#38

Whoops… came about this post in the wrong way and missed the FAQ part… Anyway might be the wrong place for them but those still are my suggestions.

A newbie tutorial would be a little tricky but at the same time… they don’t have experience with other languages or have to relearn how things work, are typically younger, I think it’d be doable. Tricky but doable. You would just have to teach them that the way Rust does variables is how variables work and you would have to hand hold them through the process and many details.

I think such a tutorial could be great for more experienced programmers too though. Because there are a few things that are a little tricky to me (I’m just getting comfortable but still don’t understand why functions need lifetimes and even re-reading that section many times in manual it doesn’t make sense to me… will ask this question in help) and if such a tutorial existed that really went into depth, I think it would help out everyone anytime something was confusing. Basically a ‘Dummies Guide to Rust’.


#39

I like the new FAQ (https://www.rust-lang.org/faq.html ), some comments:

We do not employ any particularly cutting-edge technologies.

While this is mostly true, I think this isn’t worth writing in the FAQ. Rust applies old ideas in new ways.

and help reduce the possibility of logic mistakes caused by incorrect indentation, like Apple’s goto fail bug.

This is not correct. Python indentation rules have the opposite effect. You can’t have a Apple’s goto fail bug in a Python3 with gotos because indentation is semantically significant, so it if looks correct it’s correct (unlike C).

This design choice of using Rust’s macro facilities to initialize collections will likely be extended generically to other collections in the future, enabling simple initialization of not only HashMap and Vec
But there’s no inherent reason for the current lack of support.

These are nice promises. Don’t leave unfulfilled promises like this in the FAQ for years.

Why can’t I compare floats or use them as HashMap or BTreeMap keys?

Given the answer to this question, then another question for the FAQ is:

Then why is this code compiling?

fn main() {
    let x: f64 = 0.1;
    let y: f64 = 0.1;
    println!("{}", x == y);
}

Testing exact floating point equality is tricky, you usually want to test equality within some small epsilon error, or better to compare only N bits of the mantissa, like with the (not nicely named) std.math.feqrel() function from the D standard library:
http://dlang.org/phobos/std_math.html#.feqrel

Why do I need to type the array size in the array declaration?

I suggest to add a note or a question regarding the necessity of type annotation for constants.

Here is some code illustrating this:

I don’t understand what’s the point of that code.

The easiest way is to use Args, which provides an iterator over the input arguments.

A question to add: why is it an iterator instead of a slice?

Enabling backtraces by setting the environment variable RUST_BACKTRACE=1 helps with getting more information.

Note to add: (The stack trace is currently working badly on Windows).

How are Go and Rust similar, and how are they different?

Be careful, this question is bait… I am not sure it’s worth keeping this question in the FAQ.

More questions for the FAQ:

  • Why does Rust allows to re-define (with let) a variable multiple times in a scope?
  • Is currently something like C alloca() or Variable Length Arrays in Rust?
  • How to increase the max stack size of a program?

#40

I really like the FAQ as well but I find it a bit hidden on the page. Considering how great (imo) it is I would even promote it to one of the first links on top of the page.


#41

cough collect-mac cough

But it is asked with some regularity.

This one, however, I’ve seen asked maybe once before?