Doc review request: pointer/rc utilities

repo | erasable | ptr-union | rc-borrow | rc-box | tracking issue

I've written a family of four small pointer pointer utility crates. Note that these apply to all (smart) pointers, not just raw ones. In overview, the four crates are:

  • erasable: Type-erased pointers. This allows implementations to treat multiple pointers to different types identically (removing generics and monomorphization cost), and enables thin pointers to ?Sized types that can recover a fat pointer from a type-erased pointer. (These crates do not yet provide a way to take advantage of this without doing so manually.)
  • ptr-union: Pointer-sized tagged unions of up to four erasable (smart) pointers by storing the tag in the alignment bits. Requires one unsafe usage to assert that the types involved are actually aligned enough for this to be sound.
  • rc-borrow: Borrowed forms of Arc and Rc. This allows you to effectively use &T (as ArcBorrow<'_, T>) but still be able to upgrade back to an owned Arc.
  • rc-box: Known unique forms of Arc and Rc. This allows them to implement DerefMut, and is primarily intended for cases where some adjustment is done to the object being reference counted when it's known statically to be unique, rather than going through the runtime cost of get_mut.

If the docs are good, I plan to publish these crates by the end of this week.

For the curious, the current crev review state:

D:\repos\cad97\pointer-utils>cargo crev crate verify
status reviews     downloads    owner  issues lines  geiger flgs crate                version         latest_t
none    0  1  1980387  14789791  3/6    0/0     538       0      unicode-xid          0.2.0           ↓0.1.0
none    0  0   898454  12694482  2/2    0/0    3052       0 CB   proc-macro2          1.0.6
pass    1  1  1899129  16203667  1/1    0/0     935       0      quote                1.0.2           =
local   0  0        ?         ?  ?/?    0/0     356      49      erasable             1.0.0-dev*
local   0  0        ?         ?  ?/?    0/0     219       0      rc-borrow            1.0.0-dev*
local   0  0        ?         ?  ?/?    0/0     461       0      rc-box               1.0.0-dev*
none    0  0   271860  18436430  1/1    0/0   25599      35 CB   syn                  1.0.11
none    0  0   379219   1469557  1/1    0/0     463       0      proc-macro-hack      0.5.11
none    0  0   128575    221297  1/1    0/0     217       0      paste-impl           0.1.6
none    0  0   128218    220750  1/1    0/0       8       0      paste                0.1.6
local   0  0        ?         ?  ?/?    0/0     367      22      ptr-union            1.0.0-dev*

I will publish crev reviews (proofs) of my crates once these are published.

Why not triomphe?

Triomphe is a great atomic reference counting library!
The main difference between triomphe and these utilities is that
triomphe implements a new Arc type that doesn't support weak references
(and as such does not have to pay the cost of handling potential weak references),
whereas these pointer utilities use the standard library's reference counting types.
If you need to work with standard library Arc/Rc, triomphe won't work for you.

If you want a more battle-tested library by the servo developers, use triomphe.
If you want small, self-contained extensions to the standard library types,
use these pointer utilities.

Additionally, triomphe only supports atomic reference counting.
We provide support for both Arc and Rc, as well as Box where applicable.

This has also been posted to r/rust.

2 Likes