Module texels

Source
Expand description

Constants for predefined texel types.

Holding an instance of Texel<T> certifies that the type T is compatible with the texel concept, that is: its alignment requirement is small enough, its size is non-zero, it does not contain any padding, and it is a plain old data type without any inner invariants (including sharing predicates). These assertions allow a number of operations such as reinterpreting aligned byte slices, writing to and read from byte buffers, fallible cast to other texels, etc.

For types that guarantee the property, see AsTexel and its impls.

§Extending

The recommended method of extending this with a custom type is by implementing bytemuck::Pod for this type. This applies a number of consistency checks.

use bytemuck::{Pod, Zeroable};
use image_texel::{AsTexel, Texel};

#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
struct Rgb(pub [u8; 3]);

impl AsTexel for Rgb {
    fn texel() -> Texel<Rgb> {
        Texel::for_type().expect("verified by bytemuck and image_texel")
    }
}

impl Rgb {
    const TEXEL: Texel<Self> = match Texel::for_type() {
        Some(texel) => texel,
        None => panic!("compilation error"),
    };
}

Structs§

AtomicBuffer
Allocates and manages atomically shared bytes.
AtomicRef
A logical reference to a typed element from some atomic memory.
AtomicSliceRef
A logical reference to a byte slice from some atomic memory.
Buffer
Allocates and manages raw bytes.
CellBuffer
Allocates and manages unsynchronized shared bytes.
IsTransparentWrapper
Marker struct to denote that P is transparently wrapped in O.
MaxAligned
A byte-like-type that is aligned to the required max alignment.
MaxAtomic
Atomic equivalence of MaxAligned.
MaxCell
A cell of a byte array equivalent to MaxAligned.
TexelRange
A range representation that casts bytes to a specific texel type.
atomic_buf
An aligned slice of atomic memory.
buf
An aligned slice of memory.
cell_buf
An aligned slice of shared-access memory.

Constants§

F32
F64
I8
I16
I32
I64
ISIZE
MAX
U8
U16
U32
U64
USIZE