pub struct TexelLayout { /* private fields */ }Expand description
Describes the byte layout of an texture element, untyped.
This is not so different from Texel and Layout but is a combination of both. It has the
same invariants on alignment as the former which being untyped like the latter. The alignment
of an element must be at most that of MaxAligned and the size must be a multiple of its
alignment.
This type is a lower semi lattice. That is, given two elements the type formed by taking the
minimum of size and alignment individually will always form another valid element. This
operation is implemented in the Self::infimum method.
Implementations§
Source§impl TexelLayout
impl TexelLayout
Sourcepub const MAX_SIZE: Self
pub const MAX_SIZE: Self
An element with maximum size and no alignment requirements.
This constructor is mainly useful for the purpose of using it as a modifier. When used with
Self::infimum it will only shrink the alignment and keep the size unchanged.
Sourcepub fn from_pixel<P: AsTexel>() -> Self
pub fn from_pixel<P: AsTexel>() -> Self
Construct an element from a self-evident pixel.
Sourcepub fn with_layout(layout: Layout) -> Option<Self>
pub fn with_layout(layout: Layout) -> Option<Self>
Create an element for a fictional type with specific layout.
It’s up to the caller to define or use an actual type with that same layout later. This skips the check that such a type must not contain any padding and only performs the layout related checks.
Sourcepub fn layout(self) -> Layout
pub fn layout(self) -> Layout
Convert this into a type layout.
This can never fail as TexelLayout refines the standard library layout type.
Sourcepub fn packed(self, align: usize) -> TexelLayout
pub fn packed(self, align: usize) -> TexelLayout
Reduce the alignment of the element.
This will perform the same modification as repr(packed) on the element’s type.
§Panics
This method panics if align is not a valid alignment.
Sourcepub fn infimum(self, other: Self) -> TexelLayout
pub fn infimum(self, other: Self) -> TexelLayout
Create an element having the smaller of both sizes and alignments.
pub const fn superset_of(&self, other: TexelLayout) -> bool
Trait Implementations§
Source§impl Clone for TexelLayout
impl Clone for TexelLayout
Source§fn clone(&self) -> TexelLayout
fn clone(&self) -> TexelLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for TexelLayout
Source§impl Debug for TexelLayout
impl Debug for TexelLayout
impl Eq for TexelLayout
Source§impl<T> From<Texel<T>> for TexelLayout
Convert a pixel to an element, discarding the exact type information.
impl<T> From<Texel<T>> for TexelLayout
Convert a pixel to an element, discarding the exact type information.
Source§impl Hash for TexelLayout
impl Hash for TexelLayout
Source§impl Ord for TexelLayout
impl Ord for TexelLayout
Source§fn cmp(&self, other: &TexelLayout) -> Ordering
fn cmp(&self, other: &TexelLayout) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TexelLayout
impl PartialEq for TexelLayout
Source§fn eq(&self, other: &TexelLayout) -> bool
fn eq(&self, other: &TexelLayout) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for TexelLayout
The partial order of elements is defined by comparing size and alignment.
impl PartialOrd for TexelLayout
The partial order of elements is defined by comparing size and alignment.
This turns it into a semi-lattice structure, with infimum implementing the meet operation. For example, the following comparison all hold:
let u8 = TexelLayout::from(U8);
let u8x2 = TexelLayout::from(U8.array::<2>());
let u8x3 = TexelLayout::from(U8.array::<3>());
let u16 = TexelLayout::from(U16);
assert!(u8 < u16, "due to size and alignment");
assert!(u8x2 < u16, "due to its alignment");
assert!(!(u8x3 < u16) && !(u16 < u8x3), "not comparable");
let meet = u8x3.infimum(u16);
assert!(meet <= u8x3);
assert!(meet <= u16);
assert!(meet == u16.packed(1), "We know it precisely here {:?}", meet);