Taking suggestions for the new Rust FAQ!

Hello everyone,

As part of the current push to improve the Rust website, we are seeking input on what to include in the new and improved Frequently Asked Questions page.

If you have questions about Rust, suggestions for concepts that should be clarified via the FAQ, or any other ideas related to this issue, feel free to share them here.

More specifically:

  • What questions do you or have you had about Rust?
  • What problems have you encountered during your experiences programming in Rust?
  • What topics or concepts in Rust do you feel deserve clarification?
  • Do you have any other ideas or comments about what the Frequently Asked Questions page on the Rust website should include?

Thanks for any and all input you can offer! Each answer helps make the Rust learning experience better.

2 Likes

Woo! Thanks for steering this @alilleybrinker

A few off the top of my head:

  • Why is Rust's HashMap so slow?
  • Why doesn't Rust support try/catch?
  • Why can't I compare floats? Why the split between Eq/PartialEq, Ord/PartialOrd?
1 Like
  • Why curly braces? Why cant everything be like Haskell/Python?
  • Why lifetimes? They seem unnecessary.
  • Whats the deal with unwrap everywhere?
  • How do i try/catch in Rust?
  • I already write perfect C/C++, what does Rust give me?

^ All questions that I have heard before.

2 Likes

OK, son now that I have some experience with the language and more or less both questions have been answered, but in my beginning I had some trouble with them :sweat_smile:

  • How do lifetimes work? When do I need to put them and why?
    I had to try almost every combination to figure out how the syntax was. Did I have to put them in impl? only in the struct definition? in impl and after the struct name? and in methods? why so many lifetime specifiers? As an example:
pub struct Planet<'p> {
...
}
impl<'p>  Planet<'p> {
...
}

I even had suggestions from the compiler of putting the lifetime specifier in the Planet::new() function definition :flushed: I get that they are important to the language now (even if with one definition should be enough) but for a newbie, the compiler messages were troublesome, well, nothing like the thread in the Internals forum to understand it.

  • Why no exceptions? I get that the Result structure can do pretty much the same thing, but propagating exceptions through the call stack could be great to keep loose coupling between some modules.
1 Like

:crying_cat_face:

Here's a list I started of some of the most frequent questions I see on IRC (with answers): https://etherpad.mozilla.org/rust-irc-faq

The questions so far are:

  • Why do I get an error when I try to run example code that uses the try! macro?
  • Can I use unstable features in the beta or stable channel?
  • Can I run benchmarks using test::Bencher on the beta or release channel?
  • How can I convert a String or Vec<T> to a slice (&str or &[T])?
  • How can I convert from &str to String?
  • How can I join a vec (or array) of strings into a single string?
  • How can I convert a scalar value to a different numeric type?
  • How can I iterate over a Vec<T> without moving/consuming it?
  • How can I read or write numeric types like i32 or f64 in big-endian or little-endian format in a file or other byte stream?
  • How can I implement a graph or other data structure that contains cycles?
  • How can I define a struct that contains a pointer to its owner, or to one of its own fields?
  • How can I convert a C-style enum to an integer, and vice-versa?
  • Where do I report issues in the Rust documentation?
2 Likes

A pretty common one I've seen on StackOverflow, etc.: "How do I read a file into a String?"

Related questions (maybe):

  • How do split a string into lines?
  • How do I join a Vec<String> with newlines?

Frequently asked questions also include things like:

  • How can I make an HTTP request?
  • How can I write a GUI application with Rust?
  • How can I parse JSON/XML?

What exactly does it mean "to consume a value"?
What is the difference between consuming vs. moving / taking ownership?

  • 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!
2 Likes

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 { ??
1 Like
  • 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?

1 Like
  • How do you configure cargo proxy ?
1 Like

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.

3 Likes

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:

1 Like

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.)