Yes. You can implement naive linked lists without unsafe.
-
-
OK. I meant that if the type system Rust bases its memory-safety on didn't admit *any* way to do linked lists without unsafe, the whole formalism would be a lot less impressive/valuable than I thought it was...
2 replies 0 retweets 0 likes -
I didn't even know it was possible, now I want to learn what a linked list looks like without using unsafe
2 replies 0 retweets 2 likes -
Replying to @andy_kelley @RichFelker and
use Rc and Weak Presumably y'all are talking about doubly linked lists, singly linked lists are possible to do efficiently in safe code
4 replies 0 retweets 6 likes -
Replying to @ManishEarth @andy_kelley and
There's also the possibility of using non-pointer references to represent the graph, such as indices into an array or some other pool data structure that holds the nodes
4 replies 0 retweets 8 likes -
Replying to @jckarter @ManishEarth and
This is the right answer in practice, if LinkedList<T> doesn’t work for you.
1 reply 0 retweets 2 likes -
I mean, for 99.9% of "practice" the right answer is "don't use a linked list", but for the remaining 0.1% ...
3 replies 0 retweets 3 likes -
Replying to @stephentyrone @pcwalton and
Linked lists have a really important property: each node can be pre-allocated, and with a separate owner. You can have a static global node, a heap-allocated node, an intrusive node in a struct field, all part of the same linked list, with no possibility of memory allocation fail
2 replies 0 retweets 3 likes -
Replying to @andy_kelley @stephentyrone and
Cases like that seem like fine candidates for `unsafe`, since you're relying on the global interaction of different ownership regimes, and making that mechanically safe is probably getting into theorem prover territory
1 reply 0 retweets 4 likes -
Replying to @jckarter @andy_kelley and
Maybe "do you need unsafe blocks" is the wrong question. How about "can you prove the unsafe blocks correct, and how do you validate and maintain the proof as the code changes?"
1 reply 0 retweets 6 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.