#ref #cell #owning-ref


Smart pointers: ARef, that allows even further owner erasure than OwningRef. Strong is a memory efficient Rc + RefCell in one. And more!

10 releases (5 breaking)

0.7.0 Jan 29, 2022
0.6.1 Aug 21, 2021
0.6.0 Nov 17, 2019
0.5.1 Nov 8, 2018
0.4.1 Nov 26, 2016

#1699 in Rust patterns

Download history 24/week @ 2023-07-29 22/week @ 2023-08-05 17/week @ 2023-08-12 43/week @ 2023-08-19 19/week @ 2023-08-26 19/week @ 2023-09-02 30/week @ 2023-09-09 37/week @ 2023-09-16 19/week @ 2023-09-23 31/week @ 2023-09-30 8/week @ 2023-10-07 95/week @ 2023-10-14 28/week @ 2023-10-21 31/week @ 2023-10-28 35/week @ 2023-11-04 8/week @ 2023-11-11

103 downloads per month



Assorted smart pointers for Rust.

API Docs



Strong / Weak / Ref / RefMut

This is like Rc<RefCell<T>>, but with slightly different trade-offs:

  • Configurable overhead (compared to a fixed 24 or 12 for Rc<RefCell<T>>)

  • The default of 4 bytes overhead gives you max 1024 immutable references, 1024 strong references and 1024 weak references, but this can easily be tweaked with just a few lines of code.

  • Poisoning support - after a panic with an active mutable reference, trying to get mutable or immutable references will return an error. This can be reverted by calling unpoison().

There is also a thread-safe version which is something like an Arc<RwSpinlock<T>>.


ARef takes over where OwningRef ends, by abstracting the owner even further.

This makes it possible to return, say, an ARef<str> and have the caller drop the owner when done looking at it, without having to bother about whether the owner is a String, Rc<String>, a Ref<String>, a simple &'static str or something else.

It's also repr(C), so it can be transferred over an FFI boundary (if its target is repr(C), too).


The RMBA wraps either a &T, &mut T, Box<T> or Arc<T> within the size of a single pointer.

It will panic if you try to store a struct that's not 32 bit aligned.

Bx, Bxm

These are just simple wrappers around Box that lets you get rid of DerefMove.

This way you can return a Bx in your API and still be sure the inner struct does not move in memory. (This might be helpful if you're dealing with FFI or unsafe code.)


Apache 2.0 or MIT, at your preference.