Skip to main content

Module storage

Module storage 

Source
Expand description

Full re-export of zenpixels core types (zero module name collisions!). Alignment-exact, #![forbid(unsafe_code)] owned pixel storage.

§Allocation / deallocation alignment rules (bytemuck & GlobalAlloc)

Rust’s core::alloc::GlobalAlloc::dealloc requires every allocation to be freed with the exact same Layout (byte capacity and alignment) that allocated it. Therefore:

  • A Vec<u8> (align = 1) can never become a Vec<u16> (align = 2) or Vec<Rgb<u16>> (align = 2) without copying, even if glibc happens to return an even pointer.
  • Conversely, Vec<Rgb<u16>> (align = 2, size = 6) can move zero-copy to and from Vec<u16> (align = 2, size = 2) via [bytemuck::allocation::try_cast_vec] whenever both length and capacity in bytes are multiples of size_of::<Rgb<u16>>() (6).
  • AlignedSamples allocates Vec<Chunk> with #[repr(C, align(64))], so its base address is always 64-byte aligned (divisible by 1, 2, 4, 8, 16, 32, 64 for zero-copy slice borrowing via bytemuck::cast_slice), and it always deallocates with align = 64 (never UB-cast to Vec<u8>).
  • On 32-bit targets where align_of::<u64>() may differ from align_of::<f64>(), F64 checks exact alignment equality before casting.

Structs§

AlignedSamples
Owned byte storage whose first byte is guaranteed 64-byte aligned on every allocator.
ExternalMutStorage
Type-erased mutable external owned backing storage (Box<[T]>, custom-allocator wrappers, mutable pool leases, FFI writable buffers).
ExternalStorage
Type-erased immutable external owned backing storage (Arc<[T]>, &'static [T], memory-mapped files, shared buffer pools, FFI read-only buffers).

Enums§

PixelStorage
Alignment-exact owned pixel backing storage.
StorageError
Low-level storage allocation error.

Traits§

ByteStorage
Read access to native-endian pixel bytes without copying.
ByteStorageMut
Mutable access to native-endian pixel bytes without copying.
StorageSample
Sealed trait implemented by the 11 native sample types stored in PixelStorage.