Alice Ryhl
๐ค SpeakerAppearances Over Time
Podcast Appearances
It's not that foreign.
I think the most tricky thing people run into is how should you put together your data structure?
I mean, for your code, you can mostly do the same things as you can in other languages.
I mean, that's not entirely true, but the big thing is really the data structures.
So if you have, I don't know what would be a good example, let's say some sort, okay, let's just say you have an object for a book, and it has an array of pages, and then you have an object for each page.
If I was writing TypeScript, I would probably have a book field in the page that references the book, and then the book, of course, also references the page.
Right, so it's cyclic.
So the book goes to the page, goes back to the book.
And in Rust, you usually have to design your objects so that they're not cyclic.
It has to be a tree or a deck, if you know what that means.
So if you go out and actually start to use reference counting, it becomes possible to have cyclic objects.
with some cavities like you mentioned, but what people end up doing when they're learning the language is that they try to make cyclic objects without anything like that.
And then it just doesn't work.
and they're going to run into all sorts of problems in their code while they're constructing, they're maybe creating their thing, and then they get a compiler error, and then they try to change the code, and they get a compiler error again.
But the thing that a lot of people struggle with is that they keep trying to change the code when the solution is to change the struct.
The ownership is just the idea that if you have a variable,
containing some object, then the object is only there.
It's kind of exclusive.
So for example, if you have a variable, let A equals your string or whatever, and then you do let B equal to A, then this is a move.
And so this means that using A afterwards is now a compiler error because its contents have been moved away.