pub struct TyAndLayout<'a, Ty> {
    pub ty: Ty,
    pub layout: Layout<'a>,
}
Expand description

The layout of a type, alongside the type itself. Provides various type traversal APIs (e.g., recursing into fields).

Note that the layout is NOT guaranteed to always be identical to that obtained from layout_of(ty), as we need to produce layouts for which Rust types do not exist, such as enum variants or synthetic fields of enums (i.e., discriminants) and fat pointers.

Fields

ty: Tylayout: Layout<'a>

Implementations

Returns Homogeneous if this layout is an aggregate containing fields of only a single type (e.g., (u32, u32)). Such aggregates are often special-cased in ABIs.

Note: We generally ignore fields of zero-sized type when computing this value (see #56877).

This is public so that it can be used in unit tests, but should generally only be relevant to the ABI details of specific targets.

Returns true if the layout corresponds to an unsized type.

Returns true if the type is a ZST and not unsized.

Determines if this type permits “raw” initialization by just transmuting some memory into an instance of T.

init_kind indicates if the memory is zero-initialized or left uninitialized.

This code is intentionally conservative, and will not detect

  • zero init of an enum whose 0 variant does not allow zero initialization
  • making uninitialized types who have a full valid range (ints, floats, raw pointers)
  • Any form of invalid value being made inside an array (unless the value is uninhabited)

A strict form of these checks that uses const evaluation exists in rustc_const_eval::might_permit_raw_init, and a tracking issue for making these checks stricter is https://github.com/rust-lang/rust/issues/66151.

FIXME: Once all the conservatism is removed from here, and the checks are ran by default, we can use the const evaluation checks always instead.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Feeds this value into the given Hasher. Read more

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

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

This method tests for !=.

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.

Layout

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.