One of the current goals is to lower the learning curve. While I love rust’s explicitness and consitency in using core its concepts on the one hand, they are parts implemented in a way they make them an obstacle for beginners. Therefore I’ve created this list of things which I encountered as being confusing or unnecessarily complex while writing code.
Some of these ideas are purely about rust, while others are inspired by the best parts in other programming languages. Surely not all of those ideas can eventually be implemented, but I still think that they are a valuable resource for improving the rust experience, especially for beginners.
Simpler Generics
Currently, if I want write a function taking an Iterator
, I have to write
something like this, defining an imho pointless constant U
:
fn take_iterator<U: Iterator>(iterator: U) {
// ...
}
This requires extra effort for beginners (using generic the compiler optimizes away vs.
using the actual implementation) and bloats the code. As the compiler
knows about Iterator
being a trait, why can’t it just create the generic-definition itself?
If it’s about the explicitness, I’d be glad about something like this instead:
fn take_iterator(iterator: <Iterator>) {
// ...
}
Shorten the Compiler’s Type Errors
When there are type mismatches, which can be caused by a variety of problems, the compiler tends to print extremly long lines creating badly understandable error messages. Those error messages should be broken down to fit in a 120 char line. It would be an extra sugar if the compiler would also propose specific solutions.
Side note: I love the “new” error format
Allow tests to work through visibility and scope borders
I like the default test system, but unfortunately it does not allow testing private methods in different files without add javasriptish complexity. It can be argued about wether one should test private methods, but I believe this decision should be made by the project and not the language or framework.
Additionally, one must write import statements which seem to follow a different logic than the normal imports. Ideally, you’d just get the environment you’re testing from the test-decorator.
The Module System in General
Thankfully, someone has already written this down in full length. Things have gotten better with the maturing documentation, but the core problem remains: https://withoutboats.github.io/blog/rust/2017/01/04/the-rust-module-system-is-too-confusing.html
From and To in the html docs.
This is a relatively small point: In the docs, only it type from or to which can be converted should be highlighted and the rest should be hidden. Currently it is hard to read and very repetitive. Take this as an example:
http://json.rs/doc/json/enum.JsonValue.html#implementations
Slicing and Negative Indexing
Python has a very powerful slicing syntax, which rust’s range are a mainly a subset of. Let me give some example on why this super convenient and should be supported in std for at least String and Vec:
"foobar"[:3] == "foo" # Eliding indeces
"foobar"[1:-2] == "oob" # Negative means counting from the end
"foobar"[::2] == "foa" # The 3rd parameter defines the step
"foobar"[::-1] == "raboof" # This is the official way of reversing a string