Skip to main content

TexelLayout

Struct TexelLayout 

Source
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

Source

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.

Source

pub fn from_pixel<P: AsTexel>() -> Self

Construct an element from a self-evident pixel.

Source

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.

Source

pub fn layout(self) -> Layout

Convert this into a type layout.

This can never fail as TexelLayout refines the standard library layout type.

Source

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.

Source

pub fn infimum(self, other: Self) -> TexelLayout

Create an element having the smaller of both sizes and alignments.

Source

pub const fn size(self) -> usize

Get the size of the element.

Source

pub const fn align(self) -> usize

Get the minimum required alignment of the element.

Source

pub const fn superset_of(&self, other: TexelLayout) -> bool

Trait Implementations§

Source§

impl Clone for TexelLayout

Source§

fn clone(&self) -> TexelLayout

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 Copy for TexelLayout

Source§

impl Debug for TexelLayout

Source§

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

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

impl Eq for TexelLayout

Source§

impl<T> From<Texel<T>> for TexelLayout

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

Source§

fn from(texel: Texel<T>) -> Self

Converts to this type from the input type.
Source§

impl Hash for TexelLayout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for TexelLayout

Source§

fn cmp(&self, other: &TexelLayout) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TexelLayout

Source§

fn eq(&self, other: &TexelLayout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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);
Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for TexelLayout

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<P, L> PlaneOf<&L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&L) -> Option<<P as PlaneOf<&L>>::Plane>

Get the layout describing the plane.
Source§

impl<P, L> PlaneOf<&mut L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&mut L) -> Option<<P as PlaneOf<&mut L>>::Plane>

Get the layout describing the plane.
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.