> Aztec.nr API reference, v6.0.0 (mainnet and testnet). Index: https://docs.aztec.network/aztec-nr-api/mainnet/llms.txt

# Primitive type TypeDefinition

Module: `std`

A compile-time type which represents a type definition such as `struct Foo { ... }`.

A `TypeDefinition` is passed as the first argument to a macro attribute on top of a struct:

```rust
#[attr]
struct Foo {}

comptime fn attr(type_definition: TypeDefinition) {
    println(type_definition.name()); // outputs "Foo"
}
```

## Implementations

```rust
impl TypeDefinition
```

```rust
pub comptime fn add_abi(self, abi_argument: CtString)
```

```rust
pub comptime fn as_type(self) -> Type
```

Return a syntactic version of this type definition as a type. For example, `type Foo<A, B> { ... })` would return `Foo<A, B>` when called with this method.

```rust
pub comptime fn as_type_with_generics(self, generics: [Type]) -> Option<Type>
```

Return this type applied to the given generic arguments. For example, given `type Foo<A, B> { ... })` could be applied to `[quote[i32].as_type(), quote[Field].as_type()].as_vector()` to return `Foo<i32, Field>`.

If an incorrect number of generic arguments are given, this function will return None. Otherwise, this function returns Some with the resulting type inside.

```rust
pub comptime fn has_named_attribute<let N: u32>(self, name: str<N>) -> bool
```

```rust
pub comptime fn named_attribute_args<let N: u32>(self, name: str<N>) -> [[Quoted]]
```

```rust
pub comptime fn has_builtin_attribute<let N: u32>(self, name: str<N>) -> bool
```

```rust
pub comptime fn location(self) -> Location
```

```rust
pub comptime fn generics(self) -> [TypeGeneric]
```

Return each generic in this type definition.

```rust
pub comptime fn fields(self, generic_args: [Type]) -> [StructField]
```

Returns each field in this type. Any generic types used in each field type is automatically substituted with the provided generic arguments.

```rust
pub comptime fn fields_as_written(self) -> [StructField]
```

Returns each field in this type. Each type is as-is with any generic arguments unchanged. Unless the field types are not needed, users should generally prefer to use [`TypeDefinition::fields`](/aztec-nr-api/mainnet/std/primitive.TypeDefinition.md#fields) over this function if possible.

```rust
pub comptime fn module(self) -> Module
```

```rust
pub comptime fn name(self) -> Quoted
```

## Trait implementations

```rust
impl Eq for TypeDefinition
```

```rust
pub comptime fn eq(self, other: Self) -> bool
```

```rust
impl Hash for TypeDefinition
```

```rust
pub comptime fn hash<H>(self, state: &mut H)
where
    H: Hasher
```
