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.
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
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
impl Type
Sourcepub(crate) fn without_borrowed_ref(&self) -> &Type
pub(crate) fn without_borrowed_ref(&self) -> &Type
When comparing types for equality, it can help to ignore &
wrapping.
pub(crate) fn is_borrowed_ref(&self) -> bool
Sourcepub(crate) fn is_doc_subtype_of(&self, other: &Self, cache: &Cache) -> bool
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
.
pub(crate) fn primitive_type(&self) -> Option<PrimitiveType>
Sourcepub(crate) fn sugared_async_return_type(self) -> Type
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.
Sourcepub(crate) fn is_assoc_ty(&self) -> bool
pub(crate) fn is_assoc_ty(&self) -> bool
Checks if this is a T::Name
path for an associated type.
pub(crate) fn is_self_type(&self) -> bool
pub(crate) fn generic_args(&self) -> Option<&GenericArgs>
pub(crate) fn generics(&self) -> Option<Vec<&Type>>
pub(crate) fn is_full_generic(&self) -> bool
pub(crate) fn is_unit(&self) -> bool
pub(crate) fn projection(&self) -> Option<(&Type, DefId, PathSegment)>
Trait Implementations§
Source§impl FromClean<Type> for Type
impl FromClean<Type> for Type
fn from_clean(ty: Type, renderer: &JsonRenderer<'_>) -> Self
impl Eq for Type
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
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 bytesDynTrait
: 32 bytesGeneric
: 12 bytesSelfTy
: 0 bytesPrimitive
: 9 bytesBareFunction
: 16 bytesTuple
: 32 bytesSlice
: 16 bytesArray
: 32 bytesPat
: 32 bytesRawPointer
: 24 bytesBorrowedRef
: 24 bytesQPath
: 16 bytesInfer
: 0 bytesImplTrait
: 32 bytes