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

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.

§

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

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:

# // 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 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

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

Auto Trait Implementations§

§

impl DynSend for Type

§

impl DynSync for Type

§

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> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

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, R> CollectAndApply<T, R> for T

source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

source§

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

source§

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

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

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

impl<T> Filterable for T

§

fn filterable( self, filter_name: &'static str ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. 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> 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<P> IntoQueryParam<P> for P

source§

impl<T> MaybeResult<T> for T

§

type Error = !

source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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<'tcx, T> ToPredicate<'tcx, T> for T

source§

fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T

source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<Tcx, T> Value<Tcx> for T
where Tcx: DepContext,

source§

default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed ) -> T

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

impl<'a, T> Captures<'a> for T
where T: ?Sized,

source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

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
  • Primitive: 9 bytes
  • BareFunction: 16 bytes
  • Tuple: 32 bytes
  • Slice: 16 bytes
  • Array: 32 bytes
  • RawPointer: 24 bytes
  • BorrowedRef: 24 bytes
  • QPath: 16 bytes
  • Infer: 0 bytes
  • ImplTrait: 32 bytes