Skip to content

Commit

Permalink
bring back documentation for nested type requirements
Browse files Browse the repository at this point in the history
accidentally deleted in #1765
  • Loading branch information
turbolent authored Oct 4, 2022
1 parent 2f04fa3 commit 50aff9d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/language/interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,39 @@ numbers.getCount() // is 0
Interfaces cannot provide default initializers or default destructors.

Only one conformance may provide a default function.

## Nested Type Requirements

<Callout type="info">

🚧 Status: Currently only contracts and contract interfaces support nested type requirements.

</Callout>

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.

```cadence
// 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
}
}
}
```

0 comments on commit 50aff9d

Please sign in to comment.