Skip to main content

PixelStorage

Enum PixelStorage 

Source
#[non_exhaustive]
pub enum PixelStorage {
Show 14 variants U8(Vec<u8>), I8(Vec<i8>), U16(Vec<u16>), I16(Vec<i16>), F16(Vec<F16Sample>), U32(Vec<u32>), I32(Vec<i32>), F32(Vec<f32>), U64(Vec<u64>), I64(Vec<i64>), F64(Vec<f64>), Aligned64(AlignedSamples), External(ExternalStorage), ExternalMut(ExternalMutStorage),
}
Expand description

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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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.

Source

pub fn zeroed_aligned64_bytes( byte_len: usize, ) -> Result<PixelStorage, StorageError>

Allocate 64-byte SIMD-aligned zeroed storage holding at least byte_len bytes.

Source

pub fn from_external<S>(owner: S) -> PixelStorage
where S: ByteStorage + Send + Sync + 'static,

Wrap an immutable external owned buffer (Arc<[T]>, mmap, &'static [T], etc.) zero-copy.

Source

pub fn from_external_mut<S>(owner: S) -> PixelStorage
where S: ByteStorageMut + Send + Sync + 'static,

Wrap a mutable external owned buffer (Box<[T]>, custom allocator, pool lease, etc.) zero-copy.

Source

pub const fn is_external(&self) -> bool

Whether this storage is backed by an external owner (External or ExternalMut).

Source

pub const fn is_mutable_in_place(&self) -> bool

Whether mutable byte access operates in place without copy-on-write promotion.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub const fn allocation_alignment(&self) -> usize

Element alignment of the underlying heap allocation.

Source

pub fn byte_capacity(&self) -> usize

Byte capacity of the underlying allocation.

Source

pub fn can_cast_into_vec<P>(&self, target_bytes: usize) -> bool
where P: Pod,

Whether truncating to target_bytes and calling cast_into_vec::<P> will succeed zero-copy without violating deallocation alignment or capacity.

Source

pub fn byte_len(&self) -> usize

Byte length of the stored allocation.

Source

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.

Source

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

Source§

fn as_bytes(&self) -> &[u8] ⓘ

Underlying bytes in native endianness.
Source§

impl ByteStorageMut for PixelStorage

Source§

fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ

Mutable underlying bytes in native endianness.
Source§

impl Clone for PixelStorage

Source§

fn clone(&self) -> PixelStorage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PixelStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<Vec<F16Sample>> for PixelStorage

Source§

fn from(v: Vec<F16Sample>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<f32>> for PixelStorage

Source§

fn from(v: Vec<f32>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for PixelStorage

Source§

fn from(v: Vec<f64>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<i8>> for PixelStorage

Source§

fn from(v: Vec<i8>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<i16>> for PixelStorage

Source§

fn from(v: Vec<i16>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<i32>> for PixelStorage

Source§

fn from(v: Vec<i32>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<i64>> for PixelStorage

Source§

fn from(v: Vec<i64>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for PixelStorage

Source§

fn from(v: Vec<u8>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<u16>> for PixelStorage

Source§

fn from(v: Vec<u16>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<u32>> for PixelStorage

Source§

fn from(v: Vec<u32>) -> PixelStorage

Converts to this type from the input type.
Source§

impl From<Vec<u64>> for PixelStorage

Source§

fn from(v: Vec<u64>) -> PixelStorage

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.