by ainar-g · 9y ago · 0 comments
What I actually would like is a few "Books" like "Rust for C++ people", "Rust for Go people", etc. Those would describe in many examples how things that are achieved in language X using A, B, and C can be done with D in Rust.
Personally, I would like a "Rust for Gophers" book that would describe things like how does Rust do composing (that is, how to do what Go calls embedding), interfaces in Rust (with dynamic vs static dispatch), HTTP in Rust (this may be waiting for Tokio?), how to model your application's types and not get into who-owns-what traps.
Also, what I really want is some kind of a list of Rust "warts" and their explanation. Like the fact that sometimes you can't do a.b().c(), but have to write tmp = a.b(); tmp.c().
I fully agree that more of this kind of thing would be great.
Also, as someone who've tried to get into Rust three times now, I've been thinking, have you or anyone from the rust documentation team ever had sessions where you just
- take a random C++/Go/Python developer
- ask them to solve a not-too-simple but not-too-hard task, something that'll generally take them less than an hour in their "native" language, in Rust
- look and take notes on their struggle with it
This might shed some light on why people (like me) have so much trouble getting into Rust.
I'm not sure enough time has passed to tell what Rust's warts truly are. I always joke String should have been called StrBuf...
I do this, yes. This is one of the reasons I hang out in IRC so often; it's an effective way to collect these kinds of things.
More data is always better, and collecting it across multiple venues. I don't think IRC is inherently going to be a representative sample. It's one of the reasons you'll see me pushing for details in Rust threads here, for example.
- No support for default struct fields: https://github.com/rust-lang/rfcs/issues/1594
- Terrible signatures for functions that return iterators: https://www.reddit.com/r/rust/comments/2h26cj/functions_retu...
If the next push is going to be for ease-of-use, those would be two nice things to fix.
Agreed, and Vec should just be Buf! Let's fork the language. :)
I understand why &str and String are different, but why do they act like they've never heard of each other? Why do they implement such different sets of methods? Why can't they be compared for equality, so I don't always have to type "literal".to_string()?
Haskell has problems with too many string types as well (worse than Rust, because the type of their default string literals is best avoided entirely), but they fix much of the problem with the OverloadedStrings extension, which uses the type checker as something that helps you coerce string literals, instead of arguing with you.
On top of handling errors (which I understand is necessary, and which the ? operator makes easier), it requires importing BufReader and BufRead, and wrapping a reference to a file handle in BufReader.
Nobody is going to know how to do this unless they come across it in Rust By Example or on Stack Overflow. Shouldn't a standard library be able to abstract over fiddly details like this? Why is it my job to tell it how to buffer?
I say this as someone who is enthusiastic about Rust, but still learning.
Basically, I tried to create a very basic HTTP server the way I would in Go, but I kept getting all sorts of lifetime errors and kept adding stuff go get away from them. So the code has issues, lots of them. Arc<Mutex<>> was recommended by a guy at the job, I don't even know why I need an Arc here, for example.
The compiler says
consider using an explicit lifetime parameter as shown: fn handle<'a,
'b>(&self, req: server::Request<'a, 'b>,
mut res: server::Response<'a>)
But when I do that I get error: `user_index_handler` does not live long enough
And there I'm stuck. The user_index_handler is declared and initialised literally one line above. I don't understand why Rust thinks it can just delete it immediately after I've created it. a.b().c()
b here is temporary, and so is freed at the end of the line, making the return of c dangling let temp = a.b();
temp.c();
Now that the return of b() is not temporary, it will last to the end of the scope and so c is fine.