4 ms·
At some stage there was a squad on StackOverflow who closed all Rust related beginner questions and it was impossible to get started. Most devs new to Rust do n
by StreamBright 4y ago
At some stage there was a squad on StackOverflow who closed all Rust related beginner questions and it was impossible to get started. Most devs new to Rust do not understand &str and String and 99% of the content about is how implementation details backing those types are different. I have not seen any blog post, documentation about how and WHEN to use &str vs String.
I want to have a function that returns the UTC now as a string. Now what? Opening a question on SO -> question closed, here is a question about &str and String that has nothing to do with the use case and everything about the implementation details of &str. Good stuff.
I think the creator of Rust assume that if they explain where a piece of data is allocated suddenly everybody is going to be on the same page about the use of that data.
- estebank 4y agoRule of thumb: use &str when you don't need more than that, use String when creating text at runtime, returning from a function or storing it in a struct field. Using borrowed values in general in fields is best avoided until you get more comfortable with the rest of the language.
- Georgelemental 4y agoRust has no GC, so to use it you need to learn how memory allocation works. If you don't want to bother with those details, use a GC language instead of Rust. If you are struggling to learn these things, even after working through the Rust book and other commonly cited resources, my suggestion would be to drop Rust for now and learn C. In C, pointers, stack/heap, malloc/free are things you have to deal with directly, so you can see how things work under the hood. And then, when you go back to Rust, you can map your hard-earned C understanding to the Rust abstractions
- Ygg2 4y agoFirst off, Stack Overflow is super close questions happy. Asking a question without a minimum code example gets it closed before you can say MVP. Same for mark as duplicate. > Most devs new to Rust do not understand &str and String and 99% of the content about is how implementation details Looking at doc like this: https://doc.rust-lang.org/rust-by-example/std/str.html https://doc.rust-lang.org/rust-by-example/std/str.html https://stackoverflow.com/questions/24158114/what-are-the-differences-between-rusts-string-and-str https://stackoverflow.com/questions/24158114/what-are-the-di... Which part didn't convey the info you wanted? How would you convey it? Curse of Knowledge is real, so to me it looks trivial, but I started Rust before str/String were a thing. I don't know what it's like to start learning Rust. > I want to have a function that returns the UTC now as a string. Now what? Opening a question on SO -> question closed, here is a question about &str and String that has nothing to do with the use case. That's on Stack Overflow overzealous moderation. If I had a dollar for every question of mine that was closed with mark as duplicate, I'd be a richer man. Doesn't mean it was specifically Rust community. Did you consider Rust Discord? I asked few very technical questions and I got some really good answers.
- StreamBright 4y ago> Curse of Knowledge is real. I agree. I usually teach with example. Sort of here is a situation, this is your input now write something (a function, sql statement, etc.) to produce the desired outcome. While doing so I explain all the relevant details (this might be a good time to talk about different allocations for example). This works surprisingly well. If you reverse the order (talk about different allocations first) the student need to connect the dots later. I found my approach working better. Anyways, it might be only me. >> Did you consider Rust Discord? I will try that.