Struct GenericParam

pub struct GenericParam {
    pub rid: u32,
    pub token: Token,
    pub offset: usize,
    pub number: u32,
    pub flags: u32,
    pub owner: OnceLock<CilTypeReference>,
    pub constraints: CilTypeRefList,
    pub name: String,
    pub custom_attributes: CustomAttributeValueList,
}
Expand description

Represents a generic parameter definition with resolved references and owned data.

A generic parameter defines a type or method parameter that can be substituted with concrete types during instantiation. This enables generic programming with type safety and performance benefits.

§Generic Parameter Types

Parameters can be defined at different scopes:

  • Type parameters: Defined on classes, interfaces, and delegates
  • Method parameters: Defined on individual methods
  • Nested parameters: Parameters within generic types can have their own parameters

§Parameter Characteristics

Each parameter has several important properties:

  • Position: Ordinal position in the parameter list (0-based)
  • Name: Identifier used in signatures and source code
  • Constraints: Restrictions on acceptable type arguments
  • Variance: Covariance/contravariance for assignment compatibility
  • Owner: The type or method that declares the parameter

§Variance Support

Generic parameters can specify variance for type safety:

┌──────────────┬─────────────────┬─────────────────────────────┐
│ Variance     │ Keyword         │ Assignment Compatibility    │
├──────────────┼─────────────────┼─────────────────────────────┤
│ Invariant    │ (none)          │ Exact type match required   │
│ Covariant    │ out             │ Derived → Base allowed      │
│ Contravariant│ in              │ Base → Derived allowed      │
└──────────────┴─────────────────┴─────────────────────────────┘

§Constraint Types

Parameters can have various constraints:

  • Class constraint: where T : class (reference types only)
  • Struct constraint: where T : struct (value types only)
  • Constructor constraint: where T : new() (parameterless constructor)
  • Base class constraint: where T : BaseClass (inheritance requirement)
  • Interface constraints: where T : IInterface (implementation requirement)

§Owner Resolution

Generic parameters are owned by either types or methods:

  • Type ownership: Parameters declared on generic types
  • Method ownership: Parameters declared on generic methods
  • Lazy resolution: Owner is resolved when first accessed
  • Type reference: Uses CilTypeReference for unified handling

§ECMA-335 Reference

See ECMA-335, Partition II, §22.20 for the complete GenericParam table specification.

Fields§

§rid: u32

The row identifier in the GenericParam table.

This 1-based index uniquely identifies this generic parameter within the GenericParam table. Combined with the table type, it forms the parameter’s unique identity.

§token: Token

The metadata token for this generic parameter.

A crate::metadata::token::Token that uniquely identifies this generic parameter across the entire assembly. The token encodes both the table type (GenericParam) and the row ID.

§offset: usize

The byte offset of this generic parameter in the metadata tables stream.

This offset points to the start of this parameter’s row data within the metadata tables stream, used for binary parsing and navigation.

§number: u32

The ordinal position of this parameter in the parameter list.

A 2-byte index indicating the parameter’s position, numbered left-to-right starting from zero. This determines the parameter’s position in generic instantiations and signature matching.

§flags: u32

Generic parameter attribute flags indicating constraints and variance.

A 2-byte bitmask of GenericParamAttributes values that specify:

  • Variance: Covariant, contravariant, or invariant
  • Constraints: Reference type, value type, constructor constraints
  • Special flags: Additional constraint information
§owner: OnceLock<CilTypeReference>

Reference to the owner of this generic parameter.

A lazily-initialized CilTypeReference that points to either:

  • TypeDef: For type-level generic parameters
  • MethodDef: For method-level generic parameters

Uses OnceLock for thread-safe lazy initialization during owner resolution.

§constraints: CilTypeRefList

List of constraint types that apply to this parameter.

A collection of CilTypeReference entries that specify the constraints imposed on this generic parameter, such as base classes and interfaces that type arguments must satisfy.

§name: String

The name of the generic parameter.

The parameter name as it appears in source code and metadata, resolved from the strings heap. Used for reflection and debugging purposes.

§custom_attributes: CustomAttributeValueList

Custom attributes applied to this generic parameter.

A collection of custom attributes that provide additional metadata about the parameter, such as documentation or analysis annotations.

Implementations§

§

impl GenericParam

pub fn apply(self: &Arc<Self>) -> Result<()>

Apply this generic parameter to its owner type or method.

This method associates the generic parameter with its owner by adding it to the owner’s parameter collection. The owner can be either a generic type (TypeDef) or a generic method (MethodDef).

§Owner Types

The owner can be one of two types:

  • TypeDef: Generic types with type parameters (List<T>)
  • MethodDef: Generic methods with method parameters (Method<U>())
§Returns

Returns Ok(()) on successful application, or an error if:

  • Owner reference is not set or invalid
  • Owner type is not TypeDef or MethodDef
  • Method reference is weak and has been dropped
  • Parameter collection operations fail
§Errors
  • No Owner: If the owner type reference is not set
  • Invalid Owner: If the owner is not a supported type or method reference
  • Weak Reference: If a method reference has been dropped
§Runtime Impact

After successful application, the parameter will:

  • Be available in the owner’s parameter collection
  • Participate in generic instantiation and signature matching
  • Support constraint checking during type resolution
  • Enable reflection and metadata queries

Auto Trait Implementations§

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.