rustdoc::clean::types

Enum Type

Source
pub(crate) enum Type {
Show 15 variants Path { path: Path, }, DynTrait(Vec<PolyTrait>, Option<Lifetime>), Generic(Symbol), SelfTy, Primitive(PrimitiveType), BareFunction(Box<BareFunctionDecl>), Tuple(Vec<Type>), Slice(Box<Type>), Array(Box<Type>, Box<str>), Pat(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

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.

Fields

§path: Path
§

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

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

§

Generic(Symbol)

A type parameter.

§

SelfTy

The Self type.

§

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.

§

Pat(Box<Type>, Box<str>)

§

RawPointer(Mutability, Box<Type>)

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

§

BorrowedRef

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

Fields

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

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:

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 generic_args(&self) -> Option<&GenericArgs>

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

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

Source§

fn from_clean(ty: Type, renderer: &JsonRenderer<'_>) -> 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 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 Eq for Type

Source§

impl StructuralPartialEq 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
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: 32 bytes
  • DynTrait: 32 bytes
  • Generic: 12 bytes
  • SelfTy: 0 bytes
  • Primitive: 9 bytes
  • BareFunction: 16 bytes
  • Tuple: 32 bytes
  • Slice: 16 bytes
  • Array: 32 bytes
  • Pat: 32 bytes
  • RawPointer: 24 bytes
  • BorrowedRef: 24 bytes
  • QPath: 16 bytes
  • Infer: 0 bytes
  • ImplTrait: 32 bytes