Hacker News new | past | comments | ask | show | jobs | submit login

Hmm... that doesn't make sense. Weak references are for refcounted values. There does not need to be any refcounting involved here at all.



There's no safe, general way to do shared ownership without ref counting or garbage collection. You can't expect Rust to provide one; it already provides ref counting and raw pointers, which is as good as any other Non-GC language does.


Yes but single owner and refcount of 1 are semantically the same. If you want to be strict about this just keep the Rc private to the implementations and only hand out Weak<T>.


So you're suggesting we add a refcount to every value because it can be made to be semantically the same as not having one?


If you want to stay in safe Rust, sure. If that's too much overhead feel free to drop down to unsafe and do it just like in C/C++.

FWIW Rc is pretty lightweight. Arc is the heavier(and threadsafe) variant.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: