Taking suggestions for the new Rust FAQ!

  • How do I return a borrow to something I created from a function?
  • Yeah, no, really, how do I return a borrow to something I created from a function?
  • Right, but I really want to, so how do I do it?
  • Are you trying to tell me I actually, really can’t? But I can do it in C++!
  • Fine then. How do I return a closure from a function?
  • Oh you have to be kidding me!


Who is using Rust?
In which projects is Mozilla using Rust?


In my opinion the FAQ list should include also the following questions:

  • Why when I pass a struct to a function I cannot use it anymore (compiler complains about moved value), while when I pass an integer everything is fine?

  • Lifetime: when it is required to be defined?

  • Why the compiler cannot find modules from an imported crate? (see my question)

  • When it is possible to avoid writing the *?

  • How the deref coercion works?

  • Can I override operators? Which ones and how?

  • How can I implement something like C++ struct X {static int x;};?

  • Whats the large codebase that is using Rust (I would assume its Rust itself and Servo but might be interesting to be mentioned)

When some people look for info on a language they wonder if it scales to larger projects.


These are a bunch of questions I had when I started learning rust, some of which have become clear, others haven’t yet.

  1. Why is there no dictionary syntax for hashmaps, as in ruby, python, swift etc?
    hash = {hello:"world"}
  2. I can leave out parentheses on if conditions, why do I have to put brackets around single line blocks? Why is the C style not allowed?
  3. SWIFT has a syntax such as ? and ! why not rust?
  4. why do I have to declare module files with mod toplevel and cannot just use them?
  5. why does Rust have no ABI like C and makes me annotate things with extern?
  6. why does read_to_string(...) take a mutable reference to a String instead of returning a String ? example
  7. why doesn’t if let allow further conditions: if let Some(x) && x == 42 { ??

  • Why is my program compiled with cargo build (or rustc) slow?

  • Use cargo build --release to enable optimizations

  • How do read file input efficiently?

  • Use either read_to_end() or BufReader. Note that Files are opened without buffer. stdin is buffered.

  • How do I “memcpy” bytes?

  • How do you configure cargo proxy ?


Go and Rust are constantly compared as both languages are “low-level” languages. While you can find a lot of third-party blog post on the topic an official comparison would be fantastic!


I suggest this one:

Many people try to compare Rust to Go, but this is flawed. Go is an
ancient board game that emphasizes strategy. Rust is more appropriately
compared to Chess, a board game focused on low-level tactics.


Nice try, but while chess entirely uses your analytical left brain side, Go needs both the analytical left side and the artistic/pattern recognition right side :smile:. Besides of that computers have beaten humans in chess, but not in Go.
Your chess/go comparison would lead to the conclusion that Go (the language) is superior to Rust :smirk:


The linguistic side of my brain says that the quote doesn’t even cover the option of Go being a programming language ;). (quote taken from Rust for Clojurists, btw.)

  • How can I detect when a example code doesn’t work because a old year example?
  • How can I update that example to today?
  • how can I detect fast when documentation of a library is outdated? (I did spend half a day once trying to calla function in a documentation of a crate, later I asked other place and say me it was outdated)


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?


We already have an issue open about it.


@mbrubeck Wow nice list! Thanks.


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.


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?


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



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.


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.