pub enum TypeParam {
Type {
name: String,
span: Span,
doc_comment: Option<DocComment>,
default_type: Option<TypeAnnotation>,
trait_bounds: Vec<TypePath>,
},
Const {
name: String,
span: Span,
doc_comment: Option<DocComment>,
ty: TypeAnnotation,
default: Option<Expr>,
},
}Expand description
A generic parameter on a function, type, trait or impl header.
Two variants:
TypeParam::Type— the classic type-level parameter (<T>,<T: Bound>,<T = DefaultType>).TypeParam::Const— a value-level const generic parameter (<const N: int>,<const N: int = 4>). Added in B.2 of the const-generics track; B.3 binds const args at monomorphization and B.4 substitutes them into specialized bodies. Until then most consumers treat const params as a placeholder — the AST captures the name, declared type, and optional default expression so later phases can wire them end-to-end.
Variants§
Type
A type parameter: T, T: Bound, T = DefaultType.
Fields
§
doc_comment: Option<DocComment>§
default_type: Option<TypeAnnotation>Default type argument: T = int
Const
A const generic parameter: const N: int, const N: int = 4.
Parsed in B.1/B.2. Monomorphization (B.3) and body substitution (B.4) are not yet implemented — most compiler passes currently treat this variant as a stub / placeholder.
Implementations§
Source§impl TypeParam
impl TypeParam
Sourcepub fn doc_comment(&self) -> Option<&DocComment>
pub fn doc_comment(&self) -> Option<&DocComment>
The parameter’s attached doc comment, common to both variants.
Sourcepub fn trait_bounds(&self) -> &[TypePath]
pub fn trait_bounds(&self) -> &[TypePath]
Trait bounds, only present on the Type variant.
Returns an empty slice for const generics (they have no bounds).
Sourcepub fn default_type(&self) -> Option<&TypeAnnotation>
pub fn default_type(&self) -> Option<&TypeAnnotation>
Default type argument, only meaningful for the Type variant.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TypeParam
impl<'de> Deserialize<'de> for TypeParam
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TypeParam
impl RefUnwindSafe for TypeParam
impl Send for TypeParam
impl Sync for TypeParam
impl Unpin for TypeParam
impl UnsafeUnpin for TypeParam
impl UnwindSafe for TypeParam
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
Mutably borrows from an owned value. Read more