pub enum Type {
Primitive(PrimitiveInfo),
Tuple(TupleInfo),
Array(ArrayInfo),
Slice(SliceInfo),
Pointer(PointerInfo),
Reference(ReferenceInfo),
Function(FunctionInfo),
Struct(StructInfo),
TupleStruct(TupleStructInfo),
UnitStruct(UnitStructInfo),
Enum(EnumInfo),
Union(UnionInfo),
}Expand description
An enum that represents information about a reflected type. This supports basically any possible
type in Rust, including primitives, arrays, and references. Generally, the only requirement is
that the type implement the Reflected trait, though most types are also expected to
implement another trait related to information they possess not shared by other type kinds.
This is backed by core::any::TypeId, through the usage of a Key associated type on all
Reflected items, which represents a 'static version of that item, even if the item isn’t
always static. This works because lifetimes are erased for Type instances anyways.
Variants§
Primitive(PrimitiveInfo)
A primitive simple type, such as u8 or str
Tuple(TupleInfo)
A tuple type, (T0, .., Tn)
Array(ArrayInfo)
An array type, [T; N]
Slice(SliceInfo)
A slice type, [T]
Pointer(PointerInfo)
A pointer type, either *const T or *mut T
Reference(ReferenceInfo)
A reference type, either &T or &mut T
Function(FunctionInfo)
A function pointer type, fn(T1..Tn) -> T0
Struct(StructInfo)
A struct type, with named fields
TupleStruct(TupleStructInfo)
A struct type, with unnamed fields
UnitStruct(UnitStructInfo)
A struct type, with no fields
Enum(EnumInfo)
An enum type, with variants
Union(UnionInfo)
A union type, with fields
Implementations§
Source§impl Type
impl Type
Sourcepub unsafe fn new_struct<T: ?Sized + ReflectedStruct>()
pub unsafe fn new_struct<T: ?Sized + ReflectedStruct>()
Sourcepub unsafe fn new_tuple_struct<T: ReflectedTupleStruct>()
pub unsafe fn new_tuple_struct<T: ReflectedTupleStruct>()
Sourcepub unsafe fn new_unit_struct<T: ReflectedUnitStruct>()
pub unsafe fn new_unit_struct<T: ReflectedUnitStruct>()
Sourcepub unsafe fn new_enum<T: ReflectedEnum>()
pub unsafe fn new_enum<T: ReflectedEnum>()
Sourcepub unsafe fn new_union<T: ReflectedUnion>()
pub unsafe fn new_union<T: ReflectedUnion>()
Sourcepub unsafe fn from_name(name: &str) -> Option<Type>
pub unsafe fn from_name(name: &str) -> Option<Type>
Get a Type instance by name, assuming it has been instantiated beforehand.
The name provided is expected to be of a certain normalized form, which may not
be fully stable between versions. This function is also fairly slow.
Prefer Type::from or Type::from_id if possible.
Current Requirements:
- All struct names should be fully qualified, so for example the Type for Type would be
rebound::ty::Type - Any commas will be followed by spaces, and there will be no trailing commas except in the case of 1-element tuples
- References will have no lifetime
- Possibly other things
§Panics
If the function fails to acquire the global reflection lock
§Safety
This function is in no way memory unsafe, however, the format used for type names is an implementation detail, and thus may change even across patch versions.
Sourcepub fn from<T: ?Sized + Reflected>() -> Type
pub fn from<T: ?Sized + Reflected>() -> Type
Get a Type instance from any reflected type, instantiating it if necessary.
Sourcepub fn unwrap_primitive(&self) -> &PrimitiveInfo
pub fn unwrap_primitive(&self) -> &PrimitiveInfo
Get this Type as a PrimitiveInfo, panicking on failure.
Sourcepub fn unwrap_tuple(&self) -> &TupleInfo
pub fn unwrap_tuple(&self) -> &TupleInfo
Get this Type as a TupleInfo, panicking on failure.
Sourcepub fn unwrap_array(&self) -> &ArrayInfo
pub fn unwrap_array(&self) -> &ArrayInfo
Get this Type as a ArrayInfo, panicking on failure.
Sourcepub fn unwrap_slice(&self) -> &SliceInfo
pub fn unwrap_slice(&self) -> &SliceInfo
Get this Type as a SliceInfo, panicking on failure.
Sourcepub fn unwrap_pointer(&self) -> &PointerInfo
pub fn unwrap_pointer(&self) -> &PointerInfo
Get this Type as a PointerInfo, panicking on failure.
Sourcepub fn unwrap_reference(&self) -> &ReferenceInfo
pub fn unwrap_reference(&self) -> &ReferenceInfo
Get this Type as a ReferenceInfo, panicking on failure.
Sourcepub fn unwrap_function(&self) -> &FunctionInfo
pub fn unwrap_function(&self) -> &FunctionInfo
Get this Type as a FunctionInfo, panicking on failure.
Sourcepub fn unwrap_struct(&self) -> &StructInfo
pub fn unwrap_struct(&self) -> &StructInfo
Get this Type as a StructInfo, panicking on failure.
Sourcepub fn unwrap_tuple_struct(&self) -> &TupleStructInfo
pub fn unwrap_tuple_struct(&self) -> &TupleStructInfo
Get this Type as a TupleStructInfo, panicking on failure.
Sourcepub fn unwrap_unit_struct(&self) -> &UnitStructInfo
pub fn unwrap_unit_struct(&self) -> &UnitStructInfo
Get this Type as a UnitStructInfo, panicking on failure.
Sourcepub fn unwrap_enum(&self) -> &EnumInfo
pub fn unwrap_enum(&self) -> &EnumInfo
Get this Type as a EnumInfo, panicking on failure.
Sourcepub fn unwrap_union(&self) -> &UnionInfo
pub fn unwrap_union(&self) -> &UnionInfo
Get this Type as a UnionInfo, panicking on failure.