#pointers #pair #integer #value #object #packed #store

pointer-value-pair

A pair of a pointer and a small integer packed into a pointer-sized object

1 unstable release

0.1.0 Mar 18, 2022

#2205 in Data structures

MIT license

10KB
184 lines

Pointer-and-value wrapper type for Rust

This crate provides the PointerAndValue type, a wrapper over a raw *const T pointer that also packs a small integer value in the alignment bits, with the guarantee that mem::size_of::<PointerAndValue<T>>() == mem::size_of::<*const T>().

It is inspired by llvm::PointerIntPair from LLVM, and TfPointerAndBits from USD.

It also provides Cow, which is similar to std::borrow::Cow but stores either &'a T or Box<T>, and is guaranteed to be the same size as *const T.

TODOs and limitations

  • This currently does not work with pointers to zero-sized types because mem::align_of returns a minimum alignment of 1.
  • Support dynamically-sized types

No runtime deps