From 50aff9d961d197623c89250c3fb011f98661f380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 4 Oct 2022 11:06:50 -0700 Subject: [PATCH] bring back documentation for nested type requirements accidentally deleted in #1765 --- docs/language/interfaces.mdx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/language/interfaces.mdx b/docs/language/interfaces.mdx index 031906d9ac..09e2ab4f38 100644 --- a/docs/language/interfaces.mdx +++ b/docs/language/interfaces.mdx @@ -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 + + + +🚧 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. + +```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 + } + } +} +```