pointer-value-pair

Crates.iopointer-value-pair
lib.rspointer-value-pair
version0.1.0
created_at2022-03-18 21:07:23.544626+00
updated_at2022-03-18 21:07:23.544626+00
descriptionA pair of a pointer and a small integer packed into a pointer-sized object
homepage
repositoryhttps://github.com/ennis/pointer-value-pair
max_upload_size
id552908
size9,992
Alexandre Bléron (ennis)

documentation

README

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
Commit count: 8

cargo fmt