🚧 Status: Currently only contracts and contract interfaces support nested type requirements.
Interfaces can require implementing types to provide concrete nested types. For example, a resource interface may require an implementing type to provide a resource type.
// Declare a resource interface named `FungibleToken`.
//
// Require implementing types to provide a resource type named `Vault`
// which must have a field named `balance`.
//
resource interface FungibleToken {
pub resource Vault {
pub balance: Int
}
}
// Declare a resource named `ExampleToken` that implements the `FungibleToken` interface.
//
// The nested type `Vault` must be provided to conform to the interface.
//
resource ExampleToken: FungibleToken {
pub resource Vault {
pub var balance: Int
init(balance: Int) {
self.balance = balance
}
}
}