Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here is a version (https://is.gd/bFCpMq) that might be instructive. It is based on a simple ref count cycle of structs like:

    pub struct ListNode<T> {
        data: T,
        prev: Weak<RefCell<ListNode<T>>>,
        next: Rc<RefCell<ListNode<T>>>,
    }
The code linked above probably has bugs (for sure with singleton lists), but I hope you get the idea. It allows you to splice lists in and out in constant time.

Also, the code doesn't use `unsafe`. Now, you would need to use `unsafe` somewhere to actually create a list, in order to initialize the fields (or you could change the type of `next` to be `Option<...>`). However, the use of `unsafe` would be limited to that method. This tries to get at the difference between (i) occasionally using `unsafe` and (ii) having no safety guarantees at all.

There are probably lots of other pain points that you can bring up, and I'm not trying to say this should be good enough, but I thought it might help explain what is possible.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: