Type

Enum Type 

Source
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

Source

pub unsafe fn new_struct<T: ?Sized + ReflectedStruct>()

Internal function used by generated code to initialize a Type for structs

§Safety

Should only be called inside a Reflected type’s init impl

Source

pub unsafe fn new_tuple_struct<T: ReflectedTupleStruct>()

Internal function used by generated code to initialize a Type for tuple structs

§Safety

Should only be called inside a Reflected type’s init impl

Source

pub unsafe fn new_unit_struct<T: ReflectedUnitStruct>()

Internal function used by generated code to initialize a Type for unit structs

§Safety

Should only be called inside a Reflected type’s init impl

Source

pub unsafe fn new_enum<T: ReflectedEnum>()

Internal function used by generated code to initialize a Type for enums

§Safety

Should only be called inside a Reflected type’s init impl

Source

pub unsafe fn new_union<T: ReflectedUnion>()

Internal function used by generated code to initialize a Type for unions

§Safety

Should only be called inside a Reflected type’s init impl

Source

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.

Source

pub fn from_id(ty_id: &TypeId) -> Option<Type>

Get a Type instance by TypeId of its associated key, assuming it has been instantiated beforehand.

Source

pub fn from<T: ?Sized + Reflected>() -> Type

Get a Type instance from any reflected type, instantiating it if necessary.

Source

pub fn unwrap_primitive(&self) -> &PrimitiveInfo

Get this Type as a PrimitiveInfo, panicking on failure.

Source

pub fn unwrap_tuple(&self) -> &TupleInfo

Get this Type as a TupleInfo, panicking on failure.

Source

pub fn unwrap_array(&self) -> &ArrayInfo

Get this Type as a ArrayInfo, panicking on failure.

Source

pub fn unwrap_slice(&self) -> &SliceInfo

Get this Type as a SliceInfo, panicking on failure.

Source

pub fn unwrap_pointer(&self) -> &PointerInfo

Get this Type as a PointerInfo, panicking on failure.

Source

pub fn unwrap_reference(&self) -> &ReferenceInfo

Get this Type as a ReferenceInfo, panicking on failure.

Source

pub fn unwrap_function(&self) -> &FunctionInfo

Get this Type as a FunctionInfo, panicking on failure.

Source

pub fn unwrap_struct(&self) -> &StructInfo

Get this Type as a StructInfo, panicking on failure.

Source

pub fn unwrap_tuple_struct(&self) -> &TupleStructInfo

Get this Type as a TupleStructInfo, panicking on failure.

Source

pub fn unwrap_unit_struct(&self) -> &UnitStructInfo

Get this Type as a UnitStructInfo, panicking on failure.

Source

pub fn unwrap_enum(&self) -> &EnumInfo

Get this Type as a EnumInfo, panicking on failure.

Source

pub fn unwrap_union(&self) -> &UnionInfo

Get this Type as a UnionInfo, panicking on failure.

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

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

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

Performs copy-assignment from source. Read more
Source§

impl CommonTypeInfo for Type

Source§

fn name(&self) -> String

Get this type’s name
Source§

fn assoc_fns(&self) -> &'static [AssocFn]

Get the known associated functions of this type
Source§

fn assoc_consts(&self) -> &'static [AssocConst]

Get the known associated constants of this type
Source§

fn as_ref<'a>(&self, val: &'a Value<'_>) -> Result<Value<'a>, Error>

Convert a Value of this type to a reference to that value, if it’s not already a reference
Source§

fn as_mut<'a>(&self, val: &'a mut Value<'_>) -> Result<Value<'a>, Error>

Convert a Value of this type to a mutable reference to that value, if it’s not already a reference
Source§

impl Debug for Type

Source§

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

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

impl Hash for Type

Source§

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

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

Source§

impl Eq for Type

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync 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> 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, 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.