#[non_exhaustive]pub enum PixelStorage {
}Expand description
Full re-export of zenpixels core types (zero module name collisions!).
Alignment-exact owned pixel backing storage.
Stores the true sample-typed Vec<T> (or 64-byte AlignedSamples) so
Vec<u16>, Vec<Rgb<u16>>, Vec<f32>, Vec<Rgba<f32>>, etc. cross
type-erased PixelBuf boundaries zero-copy while
strictly preserving Rust’s allocation/deallocation alignment contract.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
U8(Vec<u8>)
u8 backing (align = 1).
I8(Vec<i8>)
i8 backing (align = 1).
U16(Vec<u16>)
u16 backing (align = 2).
I16(Vec<i16>)
i16 backing (align = 2).
F16(Vec<F16Sample>)
F16Sample backing (align = 2).
U32(Vec<u32>)
u32 backing (align = 4).
I32(Vec<i32>)
i32 backing (align = 4).
F32(Vec<f32>)
f32 backing (align = 4).
U64(Vec<u64>)
u64 backing (align = align_of::<u64>()).
I64(Vec<i64>)
i64 backing (align = align_of::<i64>()).
F64(Vec<f64>)
f64 backing (align = align_of::<f64>()).
Aligned64(AlignedSamples)
64-byte SIMD-aligned backing (align = 64).
External(ExternalStorage)
Immutable external owned backing (Arc<[T]>, mmap, &'static [T], shared pool).
Read access is zero-copy; mutable access promotes via copy-on-write into Aligned64.
ExternalMut(ExternalMutStorage)
Mutable external owned backing (Box<[T]>, custom allocator, pool lease, FFI buffer).
Both read and write access are zero-copy in place.
Implementations§
Source§impl PixelStorage
impl PixelStorage
Sourcepub fn zeroed_bytes(
sample: SampleType,
byte_len: usize,
) -> Result<PixelStorage, StorageError>
pub fn zeroed_bytes( sample: SampleType, byte_len: usize, ) -> Result<PixelStorage, StorageError>
Allocate zeroed storage with exact alignment for sample, holding at least byte_len bytes.
Sourcepub fn zeroed_aligned64_bytes(
byte_len: usize,
) -> Result<PixelStorage, StorageError>
pub fn zeroed_aligned64_bytes( byte_len: usize, ) -> Result<PixelStorage, StorageError>
Allocate 64-byte SIMD-aligned zeroed storage holding at least byte_len bytes.
Sourcepub fn from_external<S>(owner: S) -> PixelStorage
pub fn from_external<S>(owner: S) -> PixelStorage
Wrap an immutable external owned buffer (Arc<[T]>, mmap, &'static [T], etc.) zero-copy.
Sourcepub fn from_external_mut<S>(owner: S) -> PixelStorage
pub fn from_external_mut<S>(owner: S) -> PixelStorage
Wrap a mutable external owned buffer (Box<[T]>, custom allocator, pool lease, etc.) zero-copy.
Sourcepub const fn is_external(&self) -> bool
pub const fn is_external(&self) -> bool
Whether this storage is backed by an external owner (External or ExternalMut).
Sourcepub const fn is_mutable_in_place(&self) -> bool
pub const fn is_mutable_in_place(&self) -> bool
Whether mutable byte access operates in place without copy-on-write promotion.
Sourcepub fn external_ref<S>(&self) -> Option<&S>where
S: 'static,
pub fn external_ref<S>(&self) -> Option<&S>where
S: 'static,
Borrow the external owner if this storage holds an external owner of concrete type S.
Sourcepub fn external_mut<S>(&mut self) -> Option<&mut S>where
S: 'static,
pub fn external_mut<S>(&mut self) -> Option<&mut S>where
S: 'static,
Mutably borrow the external owner if this storage is ExternalMut of concrete type S.
Sourcepub fn into_external<S>(self) -> Result<S, PixelStorage>where
S: 'static,
pub fn into_external<S>(self) -> Result<S, PixelStorage>where
S: 'static,
Recover an immutable external owner S zero-copy; returns Err(self) untouched otherwise.
Sourcepub fn into_external_mut<S>(self) -> Result<S, PixelStorage>where
S: 'static,
pub fn into_external_mut<S>(self) -> Result<S, PixelStorage>where
S: 'static,
Recover a mutable external owner S zero-copy; returns Err(self) untouched otherwise.
Sourcepub fn try_cow_bytes_mut(&mut self) -> Result<&mut [u8], StorageError>
pub fn try_cow_bytes_mut(&mut self) -> Result<&mut [u8], StorageError>
Fallibly obtain mutable bytes, performing copy-on-write promotion into 64-byte aligned
owned storage if backed by immutable PixelStorage::External.
Never fails merely because storage is immutable External; returns
Err(StorageError::AllocationFailed) only on OOM during copy-on-write promotion.
Strictly zero-copy and infallible for native Vec, Aligned64, and ExternalMut.
Sourcepub fn from_rows<'r>(
sample: SampleType,
total_bytes: usize,
rows: impl Iterator<Item = &'r [u8]>,
) -> Result<PixelStorage, StorageError>
pub fn from_rows<'r>( sample: SampleType, total_bytes: usize, rows: impl Iterator<Item = &'r [u8]>, ) -> Result<PixelStorage, StorageError>
Gather row slices into fresh tightly packed storage of sample’s native alignment.
Sourcepub fn adopt_vec<P>(
pixels: Vec<P>,
sample: SampleType,
) -> Result<PixelStorage, Vec<P>>where
P: Pod,
pub fn adopt_vec<P>(
pixels: Vec<P>,
sample: SampleType,
) -> Result<PixelStorage, Vec<P>>where
P: Pod,
Move a typed Vec<P> into native PixelStorage zero-copy when
align_of::<P>() and capacity match sample’s backing layout.
On mismatch (e.g., an over-aligned pixel type), returns Err(pixels)
untouched without allocating.
Sourcepub fn cast_into_vec<P>(self) -> Result<Vec<P>, PixelStorage>where
P: Pod,
pub fn cast_into_vec<P>(self) -> Result<Vec<P>, PixelStorage>where
P: Pod,
Move this storage into Vec<P> zero-copy when align_of::<P>()
matches the backing allocation’s exact alignment AND both active byte
length and byte capacity are exact multiples of size_of::<P>().
Returns Err(self) untouched otherwise (never UB, never copies).
Sourcepub fn into_sample_vec<T>(self) -> Result<Vec<T>, PixelStorage>where
T: StorageSample,
pub fn into_sample_vec<T>(self) -> Result<Vec<T>, PixelStorage>where
T: StorageSample,
Extract the exact sample-typed Vec<T> zero-copy when the variant matches.
Sourcepub const fn allocation_alignment(&self) -> usize
pub const fn allocation_alignment(&self) -> usize
Element alignment of the underlying heap allocation.
Sourcepub fn byte_capacity(&self) -> usize
pub fn byte_capacity(&self) -> usize
Byte capacity of the underlying allocation.
Sourcepub fn can_cast_into_vec<P>(&self, target_bytes: usize) -> boolwhere
P: Pod,
pub fn can_cast_into_vec<P>(&self, target_bytes: usize) -> boolwhere
P: Pod,
Whether truncating to target_bytes and calling cast_into_vec::<P>
will succeed zero-copy without violating deallocation alignment or capacity.
Sourcepub fn try_clone(&self) -> Result<PixelStorage, StorageError>
pub fn try_clone(&self) -> Result<PixelStorage, StorageError>
Fallibly clone the underlying storage without panicking on OOM.
External storage variants clone their active bytes into 64-byte aligned owned storage.
Sourcepub fn truncate_bytes(&mut self, bytes: usize)
pub fn truncate_bytes(&mut self, bytes: usize)
Truncate active byte count in place (rounded up to whole sample units).
Trait Implementations§
Source§impl ByteStorage for PixelStorage
impl ByteStorage for PixelStorage
Source§impl ByteStorageMut for PixelStorage
impl ByteStorageMut for PixelStorage
Source§fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Source§impl Clone for PixelStorage
impl Clone for PixelStorage
Source§fn clone(&self) -> PixelStorage
fn clone(&self) -> PixelStorage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more