Struct Type

Source
pub struct Type { /* private fields */ }
Expand description

A reference to internally stored type information. A Type can be used to query information, construct other types, or store type information for later use.

Implementations§

Source§

impl Type

Source

pub fn collect_unreferenced_type_data() -> TypeCollectionStats

Collects all data related to types that are no longer referenced by a Type. Returns the number of types that were removed.

Source

pub fn new_struct( name: impl Into<String>, layout: Layout, guid: Guid, fields: impl IntoIterator<Item = (String, Type, u16)>, memory_kind: StructMemoryKind, ) -> Type

Constructs a new struct type

Source

pub fn name(&self) -> &str

Returns the name of the type

Source

pub fn value_layout(&self) -> Layout

Returns the memory layout of the data of the type. This is the layout of the memory when stored on the stack or in the heap.

Source

pub fn reference_layout(&self) -> Layout

Returns the layout of the type when being referenced.

Source

pub fn is_reference_type(&self) -> bool

Returns true if the type is a reference type. Variables of reference types store references to their data (objects), while variables of value types directly contain their data.

Source

pub fn is_value_type(&self) -> bool

Returns true if the type is a value type. Variables of reference types store references to their data (objects), while variables of value types directly contain their data.

Source

pub fn equals<T>(&self) -> bool
where T: HasStaticType,

Returns true if this instance represents the TypeInfo of the given type.

assert!(i64::type_info().equals::<i64>());
assert!(!i64::type_info().equals::<f64>())
Source

pub fn is_primitive(&self) -> bool

Returns whether this is a fundamental type.

Source

pub fn is_struct(&self) -> bool

Returns whether this is a struct type.

Source

pub fn is_pointer(&self) -> bool

Returns whether this is a pointer type.

Source

pub fn is_array(&self) -> bool

Returns whether this is an array type.

Source

pub fn kind(&self) -> TypeKind<'_>

Returns the kind of the type

Source

pub fn is_concrete(&self) -> bool

Returns true if this type is a concrete type. This is the case for any type that doesn’t refer to another type like a pointer.

Source

pub fn as_concrete(&self) -> Option<&Guid>

Returns the GUID associated with this instance if this instance represents a concrete type.

Source

pub fn as_struct(&self) -> Option<StructType<'_>>

Retrieves the type’s struct information, if available.

Source

pub fn as_pointer(&self) -> Option<PointerType<'_>>

Retrieves the type’s pointer information, if available.

Source

pub fn as_array(&self) -> Option<ArrayType<'_>>

Retrieves the type’s array information, if available.

Source

pub fn try_from_abi<'abi>( type_info: impl IntoIterator<Item = &'abi TypeDefinition<'abi>>, type_table: TypeTable, ) -> Result<(TypeTable, Vec<Type>), TryFromAbiError<'abi>>

Tries to convert multiple abi::TypeDefinition to internal type representations. If the conversion succeeds an updated TypeTable is returned

Source

pub fn pointer_type(&self, mutable: bool) -> Type

Returns the type that represents a pointer to this type

Source

pub fn array_type(&self) -> Type

Returns the type that represents an array to this type

Source

pub fn into_raw(ty: Type) -> *const c_void

Consumes the Type, returning a wrapped raw pointer.

After calling this function, the caller is responsible for the memory previously managed by the Type. The easiest way to do this is to convert the raw pointer back into a Type with the Type::from_raw function, allowing the Type destructor to perform the cleanup.

Source

pub unsafe fn from_raw(raw: *const c_void) -> Type

Constructs a box from a raw pointer.

After calling this function, the raw pointer is owned by the resulting Type. Specifically, the Type destructor will ensure the memory previously retained by the raw will be properly cleaned up. For this to be safe, the passed in raw pointer must have been previously returned by Type::into_raw.

This function must also not be called as part of static deinitialization as that may cause undefined behavior in the underlying implementation. Therefor passing the raw pointer over FFI might not be safe. Instead, wrap the Type in an Arc or a Box and use that on the FFI boundary.

§Safety

This function is unsafe because improper use may lead to memory problems. For example, a double-free may occur if the function is called twice on the same raw pointer.

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Type

Source§

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

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

impl Display for Type

Source§

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

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

impl Drop for Type

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Hash for Type

Source§

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

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 PartialEq for Type

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 TypeTrace for Type

Source§

type Trace = Trace

Source§

fn trace(&self, obj: GcPtr) -> <Type as TypeTrace>::Trace

Returns an iterator to iterate over all GC objects that are referenced by the given object.
Source§

impl Eq for Type

Source§

impl Send for Type

Source§

impl Sync for Type

Auto Trait Implementations§

§

impl Freeze for Type

§

impl !RefUnwindSafe for Type

§

impl Unpin for Type

§

impl !UnwindSafe for Type

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.