4 ms·
I really hope nobody mistakes the sexy title of this book as a reason to learn unsafe rust. If it can be done without this advanced feature, it probably should.
by rattray 10y ago
I really hope nobody mistakes the sexy title of this book as a reason to learn unsafe rust. If it can be done without this advanced feature, it probably should.
- vvanders 10y ago> However if you intend to write unsafe code -- or just want to dig into the guts of the language -- this book contains invaluable information. Agreed, however I think the latter part of the intro is worthwhile to anyone who wants a deeper understanding of Rust. I've always found that a in depth understanding of what you use pays off in unforeseen ways.
- bluejekyll 10y agoIt's true. I have a 30k+ LoC project, and it has zero unsafe code blocks. Though I do have another project that exports a C API, and that requires unsafe, though it's literally only for wrapping/unwrapping pointers.
- sanderjd 10y agoAre you able to say what your project is? I'm always curious to hear about bigger projects!
- bluejekyll 10y agoSure: https://github.com/bluejekyll/trust-dns https://github.com/bluejekyll/trust-dns It's a WIP, but mostly feature complete at this point. I'm working on DNSCrypt at the moment.
- e12e 10y agoNice project. Seems a bit light on documentation? Is the intention to be a bind work-alike, or have you taken some inspiration from other servers, like eg: DJB's djbdns? [ed: just found src/config/test - looks more like a "better bind" than "djbdns in rust"]
- bluejekyll 10y agoNot sure I totally understand what you mean by djbdns in Rust. I have taken some of djb's ideas, and plan on incorporating more, like randomized QID and Port to make cache poisoning more difficult (added recently). I've implemented this from RFC's only. It's not based on any other DNS server per sé. My insiration started with yet another Bind exploit, and then grew from there. Unlike djbdns, I want this really to have as little manual operation as possible. After DNSCrypt I'm going to look at implementing a version of Raft on top of DNS updates/notifies, etc, to make server resiliency even better. DNSCrypt is next, mostly so thy I can use it for private comms between DNS nodes. djb's is amazing, but what I'm looking for is to build something more flexible and more feature rich.
- bluejekyll 10y agoRe: docs The code is well documented ;) Operational docs will come, but I haven't really had an opportunity to focus on those yet.
- kibwen 10y agoI wouldn't worry too much, the text of the book goes to great and colorful lengths to dissuade people from using these features frivolously. :)
- vertex-four 10y agoThe book actually contains a bunch of information on implementation details and other things that aren't unsafe, but just don't have a good place in the regular book. Additionally, if nobody writes unsafe Rust, who's going to maintain the abstractions that the rest of us rely on? :)
- pjmlp 10y agoLooking at Rust code with the eyes of a Wirth and Xerox Parc language fan, I still get the feeling that Rust requires too much uses of unsafe code versus Ada, Modula-3 and similar. Specially for basic data structures like trees, graphs and double linked lists.
- Gankro 10y agoI would be very interested in how these two languages enable safe data structuring. Do they have significant tradeoffs in terms of ergonomics, control, or perf? Keep in mind basically all of Rust's libcollections uses unsafe code for perf and low-level representation reasons. They can all be made safe using the strategies every other safe language uses (and eating the associated downsides). Also keep in mind Rust's data structures are basically language primitives in a lot of other languages!
- pjmlp 10y agoModula-3 has GC. You can only make use of untraced pointers in unsafe modules. So unless proven otherwise by the profiler, no need to make use of unsafe code. Ada requires explicit use of unsafe code for memory deallocation, but it is not required when using RAII pools. So unless a custom allocator is required, the standard pools can be used. In Rust even a basic double linked list requires unsafe. Then there are those that make use of unsafe to try to express code that cannot be proven by the type system, instead of plain memory corruption issues. Thankfully the core team is against this trend.
- tatterdemalion 10y ago> In Rust even a basic double linked list requires unsafe. Well this just isn't true. You can write a doubly linked list using Rc and Weak pointers and no unsafe code. This is the same as saying you can write a doubly linked list using GC'd pointers.
- geofft 10y agoI didn't see this comment when replying above, but you can write a doubly-linked list in safe Rust with either of these approaches (GC, or stuffing everything into a single giant reference). The only reason a "basic" doubly-linked list in Rust is unsafe is that those aren't really reasonable options, and Rust wants to do better. I don't think it would improve Rust to give it mandatory GC (Go and Java are both great languages if you want that), or to require that all allocations are unsafe unless you use memory pools.