[][src]Module heaparray::memory_block

Memory blocks that can hold arbitrary data on the heap. Used to represent the data that all the other types point to.

It's not recommended to use these directly; instead, use the pointer types that refer to these, namely HeapArray, FatPtrArray, and ThinPtrArray.

NOTE: TPArrayBlock is marked by the compiler as "Sized". This is incorrect, and thus it's not suggested that you use this type directly. It's suggested that you use one of either FatPtrArray or ThinPtrArray, cooresponding to FPArrayBlock and TPArrayBlock respectively.

Invariants

These are assumptions that safe code follows, and are maintained by the safe subset of the API to this struct. Please note that the unsafe API does NOT maintain these invariants, but still assumes them to be true.

  • A valid memory block cannot have a len of core::usize::MAX.
  • A valid memory block cannot have an valid index that overflows a usize
  • A valid reference to a memory block cannot have the value of core::usize::MAX
  • A valid memory block will not be zero-sized
  • A valid thin-pointer memory block has a correctly set capacity.

The invariants above are used to reduce the number of checks in the safe API, as well as to have consistent definitions for null pointers. Again, note that calls to unsafe functions do NOT check these invariants for you when doing things like constructing new types.

Structs

FPArrayBlock

An array block that keeps size information in the pointer to the block. Can additionally hold arbitrary information about the elements in the container, through the L generic type.

TPArrayBlock

An array block that keeps size information in the block itself. Can additionally hold arbitrary information about the elements in the container, through the L generic type.

Constants

NULL

Functions

block_max_len

Get the maximum length of a memory block, based on the types that it contains. Maintains the invariants discussed above.