8 ms·
> The usual solution is to put the cyclic graph code into a library, and to use pointers and about 20 lines of unsafe code. It's not much different from the C++
by pcwalton 10y ago
> The usual solution is to put the cyclic graph code into a library, and to use pointers and about 20 lines of unsafe code. It's not much different from the C++ solution.
Well, petgraph uses vectors and indices to avoid unsafe code, and it's the most popular graph library on crates.io.
Really, the answer here is "use a graph crate on crates.io". If you don't know which one to use, the best answer is probably petgraph.
> The Servo team really wants GCed, safe pointer support in Rust, and design work is well underway. But it's going to take a while to stabilize.
We aren't going to use GC'd pointers for any of the trees except the DOM. GC is way overkill for this use case. The reason why we want GC support is not to make tree data structures: it's for integration with JavaScript.
- ekidd 10y ago> Well, petgraph uses vectors and indices to avoid unsafe code, and it's the most popular graph library on crates.io. Nice! I hadn't seen that yet, but it looks really interesting: http://bluss.github.io/petgraph/doc/petgraph/graph/struct.Graph.html http://bluss.github.io/petgraph/doc/petgraph/graph/struct.Gr...
- chias 10y agoNot sure if it's just me, but the ampersands at that link are displaying super weirdly on my end: https://i.imgur.com/Bg8rejM.png https://i.imgur.com/Bg8rejM.png
- MaulingMonkey 10y agoHappens here too (on Chrome 52-53.) I guess it isn't some locally corrupted font, eh? Edit: Doesn't occur on IE 11, so it seems Chrome specific.
- iopq 10y agoIt's a locally corrupted copy of Source Code Pro. When I installed a new version it was resolved.
- iopq 10y agoIt means you have an older version of source code pro, the Rust website uses your local font instead of an invalid font name like some websites do.
- TillE 10y agoA lot of problems in Rust seem to involve replacing (smart) pointers with handles. Sometimes you really do want to do that, but it's bad if it's a necessary kludge. Like someone else said recently, it's a problem if you can't reasonably teach a basic computer science course in Rust.
- steveklabnik 10y agoThere are already some CS courses in Rust, Penn is running another one this upcoming semester. (It's not a basic course, but you absolutely could.)
- eriknstr 10y agoCIS 198 or something else? https://cis198-2016f.github.io/ https://cis198-2016f.github.io/ I am currently "attending" the above mentioned course by following along online. I am enjoying it very much so far. There have been three assignments so far, the first of which was to get rust installed and such. I think it would take most of the HN crowd less than a week to catch up with the course so that they can follow it for the remainder of the semester, even if they have a day job. The most experienced programmers might be able to catch up within just a few hours. The schedule at https://cis198-2016f.github.io/schedule/ https://cis198-2016f.github.io/schedule/ has links to the slides, lecture notes and assignments.
- steveklabnik 10y agoThat's the one!
- ekidd 10y ago"Safe" Rust works for almost everything in a typical CS curriculum. But if you want to teach an operating systems course or build cyclic, pointer-based data structures, you'll usually need a modest amount of "unsafe" Rust. Using "unsafe" gives you access to real pointers, which work just like they do in any systems language. It's just that Rust chooses to lock those features away when you don't explicitly ask for them. If you actually need "unsafe", it's no more dangerous or more difficult than writing C code.