Struct mun_memory::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
impl Type
sourcepub fn collect_unreferenced_type_data() -> TypeCollectionStats
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.
sourcepub fn new_struct(
name: impl Into<String>,
layout: Layout,
guid: Guid,
fields: impl IntoIterator<Item = (String, Type, u16)>,
memory_kind: StructMemoryKind
) -> Type
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
sourcepub fn value_layout(&self) -> Layout
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.
sourcepub fn reference_layout(&self) -> Layout
pub fn reference_layout(&self) -> Layout
Returns the layout of the type when being referenced.
sourcepub fn is_reference_type(&self) -> bool
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.
sourcepub fn is_value_type(&self) -> bool
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.
sourcepub fn equals<T: HasStaticType>(&self) -> bool
pub fn equals<T: HasStaticType>(&self) -> bool
Returns true if this instance represents the TypeInfo of the given type.
assert!(i64::type_info().equals::<i64>());
assert!(!i64::type_info().equals::<f64>())
sourcepub fn is_primitive(&self) -> bool
pub fn is_primitive(&self) -> bool
Returns whether this is a fundamental type.
sourcepub fn is_pointer(&self) -> bool
pub fn is_pointer(&self) -> bool
Returns whether this is a pointer type.
sourcepub fn is_concrete(&self) -> bool
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.
sourcepub fn as_concrete(&self) -> Option<&Guid>
pub fn as_concrete(&self) -> Option<&Guid>
Returns the GUID associated with this instance if this instance represents a concrete type.
sourcepub fn as_struct(&self) -> Option<StructType<'_>>
pub fn as_struct(&self) -> Option<StructType<'_>>
Retrieves the type’s struct information, if available.
sourcepub fn as_pointer(&self) -> Option<PointerType<'_>>
pub fn as_pointer(&self) -> Option<PointerType<'_>>
Retrieves the type’s pointer information, if available.
sourcepub fn as_array(&self) -> Option<ArrayType<'_>>
pub fn as_array(&self) -> Option<ArrayType<'_>>
Retrieves the type’s array information, if available.
sourcepub fn try_from_abi<'abi>(
type_info: impl IntoIterator<Item = &'abi TypeDefinition<'abi>>,
type_table: TypeTable
) -> Result<(TypeTable, Vec<Type>), TryFromAbiError<'abi>>
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
sourcepub fn pointer_type(&self, mutable: bool) -> Type
pub fn pointer_type(&self, mutable: bool) -> Type
Returns the type that represents a pointer to this type
sourcepub fn array_type(&self) -> Type
pub fn array_type(&self) -> Type
Returns the type that represents an array to this type
sourcepub fn into_raw(ty: Type) -> *const c_void
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.
sourcepub unsafe fn from_raw(raw: *const c_void) -> Type
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.