pub struct Texel<P: ?Sized>(_);
Expand description

Marker struct to denote a texel type.

Can be constructed only for types that have expected alignment and no byte invariants. It always implements Copy and Clone, regardless of the underlying type and is zero-sized.

This is the central encapsulation of unsafety in this crate. It utilizes bytemuck for a safe interface but permits other types with an unsafe interface, and offers the cast operations without a bound on the Pod trait. Note that Pod is a pure marker trait; its properties must hold even if it is not explicitly mentioned. If all constructors (safely or unsafely) ensure that its properties hold we can use Texel as a witness type for the bound and subsequently write interfaces to take an instance instead of having a static type bound. This achieves two effects:

  • Firstly, it makes the interface independent of the chosen transmutation crate. Potentially we will have a method to construct the Texel via a core trait.
  • Secondly, it allows creating texel of third-party types for which the bound can not be implemented. Crucially, this includes SIMD representations that would be a burden to support directly. And conversely you can also deal with arbitrary existing texel without a bound in your own interfaces!

Implementations

Try to construct an instance of the marker.

If successful, you can freely use it to access the image buffers. This requires:

  • The type must have an alignment of at most MAX_ALIGN.
  • The type must not be a ZST.
  • The type must not have any Drop-glue (no drop, any contain not part that is Drop).

Create a witness certifying P as a texel without checks.

Safety

The type P must not:

  • have any validity invariants, i.e. is mustn’t contain any padding.
  • have any safety invariants. This implies it can be copied.
  • have an alignment larger than MaxAligned.
  • be a zero-size type.

Furthermore, tentatively, the type must not have any drop glue. That is its members are all simple types without Drop implementations. This requirement exists mainly to avoid code accidentally leaking instances, and ensures that copies created from their byte representation—which is safe according to the other invairants— do not cause unexpected effects.

Proxy of core::mem::align_of.

Proxy of core::mem::size_of.

Publicly visible function to use the guarantee of non-ZST.

Construct a texel as an array of no elements.

Panics

This function panics when called with N equal to 0.

Construct a texel by wrapping into a transparent wrapper.

TODO: a constructor for Texel based on proof of transmutation from &mut P to &mut O, based on the standard transmutation RFC. This is more flexible than bytemuck’s TransparentWrapper trait.

Construct a texel by unwrapping a transparent wrapper.

Construct a texel that contains a number in the standard Wrapping type.

Construct a texel, from an array of elements.

Operations that can be performed based on the evidence of Texel.

Copy a texel.

Note that this does not require Copy because that requirement was part of the requirements of constructing this Texel witness.

Reinterpret a slice of aligned bytes as a slice of the texel.

Note that the size (in bytes) of the slice will be shortened if the size of P is not a divisor of the input slice’s size.

Reinterpret a slice of aligned bytes as a mutable slice of the texel.

Note that the size (in bytes) of the slice will be shortened if the size of P is not a divisor of the input slice’s size.

Try to reinterpret a slice of bytes as a slice of the texel.

This returns Some if the buffer is suitably aligned, and None otherwise.

Try to reinterpret a slice of bytes as a slice of the texel.

This returns Some if the buffer is suitably aligned, and None otherwise.

Reinterpret a slice of texel as memory.

Note that you can convert a reference to a single value by core::slice::from_ref.

Reinterpret a mutable slice of texel as memory.

Note that you can convert a reference to a single value by core::slice::from_mut.

Trait Implementations

This is a pure marker type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Convert a pixel to an element, discarding the exact type information.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Try to use the matrix with a specific pixel type.

Try to use the matrix with a specific pixel type.

This is a pure marker type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.