Enum rustdoc::clean::types::Type

source ·
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>, Box<str>), RawPointer(Mutability, Box<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>, Box<str>)

An array type.

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

§

RawPointer(Mutability, Box<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§

source§

impl Type

source

pub(crate) fn without_borrowed_ref(&self) -> &Type

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

source

pub(crate) fn is_borrowed_ref(&self) -> bool

source

pub(crate) fn is_doc_subtype_of(&self, other: &Self, cache: &Cache) -> bool

Check if two types are “the same” for documentation purposes.

This is different from Eq, because it knows that things like Placeholder are possible matches for everything.

This relation is not commutative when generics are involved:

# // see types/tests.rs:is_same_generic for the real test
use rustdoc::format::cache::Cache;
use rustdoc::clean::types::{Type, PrimitiveType};
let cache = Cache::new(false);
let generic = Type::Generic(rustc_span::symbol::sym::Any);
let unit = Type::Primitive(PrimitiveType::Unit);
assert!(!generic.is_same(&unit, &cache));
assert!(unit.is_same(&generic, &cache));

An owned type is also the same as its borrowed variants (this is commutative), but &T is not the same as &mut T.

source

pub(crate) fn primitive_type(&self) -> Option<PrimitiveType>

source

pub(crate) fn sugared_async_return_type(self) -> Type

Returns the sugared return type for an async function.

For example, if the return type is impl std::future::Future<Output = i32>, this function will return i32.

Panics

This function will panic if the return type does not match the expected sugaring for async functions.

source

pub(crate) fn is_assoc_ty(&self) -> bool

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

source

pub(crate) fn is_self_type(&self) -> bool

source

pub(crate) fn generics(&self) -> Option<Vec<&Type>>

source

pub(crate) fn is_full_generic(&self) -> bool

source

pub(crate) fn is_unit(&self) -> bool

source

pub(crate) fn projection(&self) -> Option<(&Type, DefId, PathSegment)>

source

fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId>

source

pub(crate) fn def_id(&self, cache: &Cache) -> Option<DefId>

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

source§

impl Type

source

pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx> ) -> impl Display + 'b + Captures<'tcx>

Trait Implementations§

source§

impl Clone for Type

source§

fn clone(&self) -> Type

Returns a copy 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 Debug for Type

source§

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

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

impl From<Type> for Term

source§

fn from(ty: Type) -> Self

Converts to this type from the input type.
source§

impl FromWithTcx<Type> for Type

source§

fn from_tcx(ty: Type, tcx: TyCtxt<'_>) -> Self

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

source§

fn eq(&self, other: &Type) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Type

source§

impl StructuralEq for Type

source§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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: 32 bytes

Size for each variant:

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