#[non_exhaustive]pub enum TypeName {
Show 13 variants
Primitive(PrimitiveType),
Named(PathType),
Reference(Lifetime, Mutability, Box<TypeName>),
Box(Box<TypeName>),
Option(Box<TypeName>),
Result(Box<TypeName>, Box<TypeName>, bool),
Writeable,
StrReference(Option<Lifetime>, StringEncoding),
PrimitiveSlice(Option<(Lifetime, Mutability)>, PrimitiveType),
StrSlice(StringEncoding),
Unit,
SelfType(PathType),
Ordering,
}Expand description
A local type reference, such as the type of a field, parameter, or return value.
Unlike CustomType, which represents a type declaration, TypeNames can compose
types through references and boxing, and can also capture unresolved paths.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Primitive(PrimitiveType)
A built-in Rust scalar primitive.
Named(PathType)
An unresolved path to a custom type, which can be resolved after all types
are collected with [TypeName::resolve()].
Reference(Lifetime, Mutability, Box<TypeName>)
An optionally mutable reference to another type.
Box(Box<TypeName>)
A Box<T> type.
Option(Box<TypeName>)
A Option<T> type.
Result(Box<TypeName>, Box<TypeName>, bool)
A Result<T, E> or diplomat_runtime::DiplomatWriteable type. If the bool is true, it’s Result
Writeable
StrReference(Option<Lifetime>, StringEncoding)
A &DiplomatStr or Box<DiplomatStr> type.
Owned strings don’t have a lifetime.
PrimitiveSlice(Option<(Lifetime, Mutability)>, PrimitiveType)
A &[T] or Box<[T]> type, where T is a primitive.
Owned slices don’t have a lifetime or mutability.
StrSlice(StringEncoding)
&[&DiplomatStr]
Unit
The () type.
SelfType(PathType)
The Self type.
Ordering
std::cmp::Ordering or core::cmp::Ordering
The path must be present! Ordering will be parsed as an AST type!
Implementations§
Source§impl TypeName
impl TypeName
Sourcepub fn to_syn(&self) -> Type
pub fn to_syn(&self) -> Type
Converts the TypeName back into an AST node that can be spliced into a program.
Sourcepub fn from_syn(ty: &Type, self_path_type: Option<PathType>) -> TypeName
pub fn from_syn(ty: &Type, self_path_type: Option<PathType>) -> TypeName
Extract a TypeName from a syn::Type AST node.
The following rules are used to infer TypeName variants:
- If the type is a path with a single element that is the name of a Rust primitive, returns a
TypeName::Primitive - If the type is a path with a single element
Box, returns aTypeName::Boxwith the type parameter recursively converted - If the type is a path with a single element
Option, returns aTypeName::Optionwith the type parameter recursively converted - If the type is a path with a single element
Selfandself_path_typeis provided, returns aTypeName::Named - If the type is a path with a single element
Result, returns aTypeName::Resultwith the type parameters recursively converted - If the type is a path equal to [
diplomat_runtime::DiplomatResult], returns a [TypeName::DiplomatResult] with the type parameters recursively converted - If the type is a path equal to [
diplomat_runtime::DiplomatWriteable], returns aTypeName::Writeable - If the type is a owned or borrowed string type, returns a
TypeName::StrReference - If the type is a owned or borrowed slice of a Rust primitive, returns a
TypeName::PrimitiveSlice - If the type is a reference (
&or&mut), returns aTypeName::Referencewith the referenced type recursively converted - Otherwise, assume that the reference is to a
CustomTypein either the current module or another one, returns aTypeName::Named
Sourcepub fn is_self(&self) -> bool
pub fn is_self(&self) -> bool
Returns true if self is the TypeName::SelfType variant, otherwise
false.
Sourcepub fn visit_lifetimes<'a, F, B>(&'a self, visit: &mut F) -> ControlFlow<B>
pub fn visit_lifetimes<'a, F, B>(&'a self, visit: &mut F) -> ControlFlow<B>
Recurse down the type tree, visiting all lifetimes.
Using this function, you can collect all the lifetimes into a collection, or examine each one without having to make any additional allocations.
Sourcepub fn any_lifetime<'a, F>(&'a self, f: F) -> bool
pub fn any_lifetime<'a, F>(&'a self, f: F) -> bool
Returns true if any lifetime satisfies a predicate, otherwise false.
This method is short-circuiting, meaning that if the predicate ever succeeds, it will return immediately.
Sourcepub fn all_lifetimes<'a, F>(&'a self, f: F) -> bool
pub fn all_lifetimes<'a, F>(&'a self, f: F) -> bool
Returns true if all lifetimes satisfy a predicate, otherwise false.
This method is short-circuiting, meaning that if the predicate ever fails, it will return immediately.
Sourcepub fn longer_lifetimes<'env>(
&self,
lifetime_env: &'env LifetimeEnv,
) -> Vec<&'env NamedLifetime>
pub fn longer_lifetimes<'env>( &self, lifetime_env: &'env LifetimeEnv, ) -> Vec<&'env NamedLifetime>
Returns all lifetimes in a LifetimeEnv that must live at least as
long as the type.
Sourcepub fn shorter_lifetimes<'env>(
&self,
lifetime_env: &'env LifetimeEnv,
) -> Vec<&'env NamedLifetime>
pub fn shorter_lifetimes<'env>( &self, lifetime_env: &'env LifetimeEnv, ) -> Vec<&'env NamedLifetime>
Returns all lifetimes in a LifetimeEnv that are outlived by the type.
pub fn is_zst(&self) -> bool
pub fn is_pointer(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TypeName
impl<'de> Deserialize<'de> for TypeName
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TypeName
impl StructuralPartialEq for TypeName
Auto Trait Implementations§
impl Freeze for TypeName
impl RefUnwindSafe for TypeName
impl Send for TypeName
impl Sync for TypeName
impl Unpin for TypeName
impl UnwindSafe for TypeName
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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:
Primitive: 1 byteNamed: 55 bytesReference: 39 bytesBox: 15 bytesOption: 15 bytesResult: 23 bytesWriteable: 0 bytesStrReference: 31 bytesPrimitiveSlice: 39 bytesStrSlice: 1 byteUnit: 0 bytesSelfType: 55 bytesOrdering: 0 bytes