by StreamBright · 3y ago · 0 comments
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.
> 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://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.
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.
Using borrowed values in general in fields is best avoided until you get more comfortable with the rest of the language.
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