Primitive type Type
Implementations
impl Type
pub comptime fn as_array(self) -> Option<(Self, Self)>
pub comptime fn as_constant(self) -> Option<u32>
If this type is a constant integer (such as the 3 in the array type [Field; 3]),
return the numeric constant.
pub comptime fn as_integer(self) -> Option<(bool, u8)>
If this is an integer type, return a boolean which is true
if the type is signed, as well as the number of bits of this integer type.
pub comptime fn as_mutable_reference(self) -> Option<Self>
If this is a mutable reference type &mut T, returns the mutable type T.
pub comptime fn as_slice(self) -> Option<Self>
If this is a slice type, return the element type of the slice.
pub comptime fn as_str(self) -> Option<Self>
If this is a str<N> type, returns the length N as a type.
pub comptime fn as_struct(self) -> Option<(TypeDefinition, [Self])>
pub comptime fn as_data_type(self) -> Option<(TypeDefinition, [Self])>
If this is a struct or enum type, returns the type in addition to any generic arguments on this type.
pub comptime fn as_tuple(self) -> Option<[Self]>
If this is a tuple type, returns each element type of the tuple.
pub comptime fn get_trait_impl(self, constraint: TraitConstraint) -> Option<TraitImpl>
Retrieves the trait implementation that implements the given
trait constraint for this type. If the trait constraint is not
found, None is returned. Note that since the concrete trait implementation
for a trait constraint specified from a where clause is unknown,
this function will return None in these cases. If you only want to know
whether a type implements a trait, use implements instead.
Example:
comptime {
let field_type = quote { Field }.as_type();
let default = quote { Default }.as_trait_constraint();
let the_impl: TraitImpl = field_type.get_trait_impl(default).unwrap();
assert(the_impl.methods().len(), 1);
}
pub comptime fn implements(self, constraint: TraitConstraint) -> bool
Returns true if this type implements the given trait. Note that unlike
get_trait_impl this will also return true for any where constraints
in scope.
Example:
fn foo<T>() where T: Default {
comptime {
let field_type = quote { Field }.as_type();
let default = quote { Default }.as_trait_constraint();
assert(field_type.implements(default));
let t = quote { T }.as_type();
assert(t.implements(default));
}
}
pub comptime fn is_bool(self) -> bool
Returns true if this type is bool.
pub comptime fn is_field(self) -> bool
Returns true if this type is Field.
pub comptime fn is_unit(self) -> bool
Returns true if this type is the unit () type.
Trait implementations
impl Eq for Type
pub comptime fn eq(self, other: Self) -> bool
Note that this is syntactic equality, this is not the same as whether two types will type check to be the same type. Unless type inference or generics are being used however, users should not typically have to worry about this distinction.
impl Hash for Type
pub comptime fn hash<H>(self, state: &mut H)
where
H: Hasher
If this type is an array, return a pair of (element type, size type).
Example: