digitalmars.D - Rust-style Ownership and Borrowing In D!
- =?UTF-8?B?Tm9yZGzDtnc=?= (25/25) Oct 12 2016 Hi!
Hi! I've recently started a new employment, and with that new collegues and new language discussions/wars ;) So there's this language Rust. And it provides some pretty amazing safety guarantees when it to memory management, algorithm correctness (preventing iterator invalidation) in both single threaded and multi-threaded contexts (task-based parallelism). One of its brightest shining showcases is Rayon: https://github.com/nikomatsakis/rayon and more specifically https://github.com/nikomatsakis/rayon#using-join-for-recursive-divide-and-conquer-problems After having given this a lot of thought I decided to think about if we can implement some of Rust's great ideas in D. My conclusion so far is that we can convert some of Rust's great compile-time checks to corresponding run-time checks in D. And use these to provide safe scope-checked reference access to non-RC C++/Rust-style containers. With a one-word memory overhead alongside the container and range/slice. Here's my proof of concept so far: https://github.com/nordlow/phobos-next/blob/master/src/borrown.d To understand it's usage start with looking at the unittests at https://github.com/nordlow/phobos-next/blob/master/src/borrown.d#L161 Note that it is used as a wrapper on top of a non-copyable array-container `Array` I've been developing the last months. Destroy!
Oct 12 2016