Skip to main content
Version: 0.17 (unstable)

Custom Types

When public component methods use custom structs or enums, those types must be annotated with #[export_type] so the compiler can include them in the component's public API. Types used only internally (in private methods or local variables) don't need this annotation.

If you forget #[export_type] on a public API type, the compiler will emit an error telling you to add it.

Exporting structs​

Struct fields must be named and use types supported by component interfaces, such as Rust primitives, SDK types (Felt, Word, Asset, etc.), or other types marked with #[export_type]:

use miden::{component, component_storage, export_type, Asset, Felt, Word};

#[export_type]
pub struct StructA {
pub foo: Word,
pub asset: Asset,
}

#[export_type]
pub struct StructB {
pub bar: Felt,
pub baz: Felt,
}

#[component_storage]
struct MyAccountStorage;

#[component]
trait MyAccount {
#[account_procedure]
fn process(&self, a: StructA) -> StructB;
}

#[component]
impl MyAccount for MyAccountStorage {
fn process(&self, a: StructA) -> StructB {
StructB {
bar: a.foo[0],
baz: a.foo[1],
}
}
}

Exporting enums​

Enums use the same annotation. Enum variants can be unit variants:

use miden::export_type;

#[export_type]
pub enum Status {
Active,
Inactive,
}

Nested types​

Exported types can reference other exported types:

#[derive(Clone, Copy, Debug)]
#[export_type]
pub struct Inner {
pub value: Felt,
}

#[derive(Clone, Copy, Debug)]
#[export_type]
pub struct Outer {
pub nested: Inner,
}

The compiler resolves references regardless of declaration order.

Types in submodules​

Custom types can be defined in submodules. Each type still needs #[export_type]:

pub mod my_types {
use miden::{Felt, export_type};

#[export_type]
pub struct StructC {
pub inner1: Felt,
pub inner2: Felt,
}
}

Rules summary​

RuleDetails
When neededAny custom type in a public method signature on a #[component] trait
StructsNamed-field and unit structs are supported; tuple structs are not
Allowed field typesSupported primitives, SDK types, Option, Result, or other #[export_type] types
EnumsUnit variants and single-field tuple variants are supported
ModulesTypes in submodules work — just apply #[export_type] to each
OrderDeclaration order doesn't matter — forward references are resolved

Full API docs on docs.rs: miden (#[export_type] macro)