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

# Primitive type Type

Module: `std`

A compile-time type which represents a type in the source program.

It can be obtained using \[`Quoted::as_type](../std/primitive.Quoted.html#as_type)`:

```rust
fn main() {
    comptime {
        let typ = quote { i32 }.as_type();
        println(typ); // outputs "i32"
    }
}
```

## Implementations

```rust
impl Type
```

```rust
pub comptime fn as_array(self) -> Option<ArrayType>
```

If this type is an array, return its element and length types.

Example:

```rust
comptime {
    let array_type = quote { [Field; 3] }.as_type();
    let array = array_type.as_array().unwrap();

    assert(array.element_type().is_field());
    assert_eq(array.length_type().as_constant().unwrap(), 3);
}
```

```rust
pub comptime fn as_constant(self) -> Option<u32>
```

If this type is a constant integer (such as the `3` in the array type `[Field; 3]`), return the numeric constant.

```rust
pub comptime fn as_integer(self) -> Option<IntegerType>
```

If this is an integer type, return its signedness and bit width.

```rust
pub comptime fn as_mutable_reference(self) -> Option<Self>
```

If this is a mutable reference type `&mut T`, returns the mutable type `T`.

```rust
pub comptime fn as_vector(self) -> Option<Self>
```

If this is a vector type, return the element type of the vector.

```rust
pub comptime fn as_str(self) -> Option<Self>
```

If this is a `str<N>` type, returns the length `N` as a type.

```rust
pub comptime fn as_data_type(self) -> Option<DataType>
```

If this is a struct or enum type, returns its [`TypeDefinition`](/aztec-nr-api/v6.0.0/std/primitive.TypeDefinition.md) and generic arguments.

```rust
pub comptime fn as_tuple(self) -> Option<[Self]>
```

If this is a tuple type, returns each element type of the tuple.

```rust
pub comptime fn get_trait_impl(self, constraint: TraitConstraint) -> Option<TraitImpl>
```

Retrieves the trait implementation that implements the given trait constraint for this type. If the trait constraint is not found, `None` is returned. Note that since the concrete trait implementation for a trait constraint specified from a `where` clause is unknown, this function will return `None` in these cases. If you only want to know whether a type implements a trait, use `implements` instead.

Example:

```rust
comptime {
    let field_type = quote { Field }.as_type();
    let default = quote { Default }.as_trait_constraint();

    let the_impl: TraitImpl = field_type.get_trait_impl(default).unwrap();
    assert(the_impl.methods().len(), 1);
}
```

```rust
pub comptime fn implements(self, constraint: TraitConstraint) -> bool
```

Returns `true` if this type implements the given trait. Note that unlike `get_trait_impl` this will also return true for any `where` constraints in scope.

Example:

```rust
fn foo<T>() where T: Default {
    comptime {
        let field_type = quote { Field }.as_type();
        let default = quote { Default }.as_trait_constraint();
        assert(field_type.implements(default));

        let t = quote { T }.as_type();
        assert(t.implements(default));
    }
}
```

```rust
pub comptime fn is_bool(self) -> bool
```

Returns `true` if this type is `bool`.

```rust
pub comptime fn is_field(self) -> bool
```

Returns `true` if this type is `Field`.

```rust
pub comptime fn is_unit(self) -> bool
```

Returns `true` if this type is the unit `()` type.

## Trait implementations

```rust
impl Eq for Type
```

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

Note that this is syntactic equality, this is not the same as whether two types will type check to be the same type. Unless type inference or generics are being used however, users should not typically have to worry about this distinction.

```rust
impl Hash for Type
```

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