pub(crate) enum Type {
Show 13 variants Path { path: Path, }, DynTrait(Vec<PolyTrait>, Option<Lifetime>), Generic(Symbol), Primitive(PrimitiveType), BareFunction(Box<BareFunctionDecl>), Tuple(Vec<Type>), Slice(Box<Type>), Array(Box<Type>, String), RawPointer(MutabilityBox<Type>), BorrowedRef { lifetime: Option<Lifetime>, mutability: Mutability, type_: Box<Type>, }, QPath(Box<QPathData>), Infer, ImplTrait(Vec<GenericBound>),
}
Expand description

Rustdoc’s representation of types, mostly based on the hir::Ty.

Variants

Path

Fields

path: Path

A named type, which could be a trait.

This is mostly Rustdoc’s version of hir::Path. It has to be different because Rustdoc’s PathSegment can contain cleaned generics.

DynTrait(Vec<PolyTrait>, Option<Lifetime>)

A dyn Trait object: dyn for<'a> Trait<'a> + Send + 'static

Generic(Symbol)

A type parameter.

Primitive(PrimitiveType)

A primitive (aka, builtin) type.

BareFunction(Box<BareFunctionDecl>)

A function pointer: extern "ABI" fn(...) -> ...

Tuple(Vec<Type>)

A tuple type: (i32, &str).

Slice(Box<Type>)

A slice type (does not include the &): [i32]

Array(Box<Type>, String)

An array type.

The String field is a stringified version of the array’s length parameter.

RawPointer(MutabilityBox<Type>)

A raw pointer type: *const i32, *mut i32

BorrowedRef

Fields

lifetime: Option<Lifetime>
mutability: Mutability
type_: Box<Type>

A reference type: &i32, &'a mut Foo

QPath(Box<QPathData>)

A qualified path to an associated item: <Type as Trait>::Name

Infer

A type that is inferred: _

ImplTrait(Vec<GenericBound>)

An impl Trait: impl TraitA + TraitB + ...

Implementations

When comparing types for equality, it can help to ignore & wrapping.

Check if two types are “potentially the same”. This is different from Eq, because it knows that things like Placeholder are possible matches for everything.

Checks if this is a T::Name path for an associated type.

Use this method to get the DefId of a clean AST node, including PrimitiveTypes.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 56 bytes

Size for each variant:

  • Path: 55 bytes
  • DynTrait: 31 bytes
  • Generic: 7 bytes
  • Primitive: 1 byte
  • BareFunction: 15 bytes
  • Tuple: 31 bytes
  • Slice: 15 bytes
  • Array: 39 bytes
  • RawPointer: 15 bytes
  • BorrowedRef: 15 bytes
  • QPath: 15 bytes
  • Infer: 0 bytes
  • ImplTrait: 31 bytes