From 7ab826fed37154a2983ba9d5d5e37d4ce12a0f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:40:04 -0300 Subject: [PATCH] update enums doc page --- apps/docs/src/guide/types/enums.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/docs/src/guide/types/enums.md b/apps/docs/src/guide/types/enums.md index a243d4c42ad..21515e37193 100644 --- a/apps/docs/src/guide/types/enums.md +++ b/apps/docs/src/guide/types/enums.md @@ -6,7 +6,7 @@ Sway Enums are a little distinct from TypeScript Enums. In this document, we wil Consider the following basic Sway Enum called `StateError`: -<<< @/../../docs-snippets/test/fixtures/forc-projects/echo-enum/src/main.sw#simple-enum-1{rust:line-numbers} +<<< @/../../docs-snippets2/sway/echo-enum/src/main.sw#enums-1{rust:line-numbers} The type `()` indicates that there is no additional data associated with each Enum variant. Sway allows you to create Enums of Enums or associate types with Enum variants. @@ -14,11 +14,11 @@ The type `()` indicates that there is no additional data associated with each En Let's define a Sway contract function that takes a `StateError` Enum variant as an argument and returns it: -<<< @/../../docs-snippets/test/fixtures/forc-projects/echo-enum/src/main.sw#simple-enum-2{rust:line-numbers} +<<< @/../../docs-snippets2/sway/echo-enum/src/main.sw#enums-2{rust:line-numbers} To execute the contract function and validate the response, we can use the following code: -<<< @/../../docs-snippets/src/guide/types/enums.test.ts#simple-enum-3{ts:line-numbers} +<<< @/../../docs-snippets2/src/types/enums.ts#enums-3{ts:line-numbers} In this example, we simply pass the Enum variant as a value to execute the contract function call. @@ -26,23 +26,23 @@ In this example, we simply pass the Enum variant as a value to execute the contr In this example, the `Error` Enum is an Enum of two other Enums: `StateError` and `UserError`. -<<< @/../../docs-snippets/test/fixtures/forc-projects/echo-enum/src/main.sw#enum-of-enums-1{rust:line-numbers} +<<< @/../../docs-snippets2/sway/echo-enum/src/main.sw#enums-4{rust:line-numbers} ### Using Enums of Enums with Contract Functions Now, let's create a Sway contract function that accepts any variant of the `Error` Enum as a parameter and returns it immediately. This variant could be from either the `StateError` or `UserError` Enums. -<<< @/../../docs-snippets/test/fixtures/forc-projects/echo-enum/src/main.sw#enum-of-enums-2{rust:line-numbers} +<<< @/../../docs-snippets2/sway/echo-enum/src/main.sw#enums-5{rust:line-numbers} Since the `Error` Enum is an Enum of Enums, we need to pass the function parameter differently. The parameter will be a TypeScript object: -<<< @/../../docs-snippets/src/guide/types/enums.test.ts#enum-of-enums-3{ts:line-numbers} +<<< @/../../docs-snippets2/src/types/enums.ts#enums-6{ts:line-numbers} In this case, since the variant `InsufficientPermissions` belongs to the `UserError` Enum, we create a TypeScript object using the Enum name as the object key and the variant as the object value. We would follow the same approach if we intended to use a variant from the `StateError` Enum: -<<< @/../../docs-snippets/src/guide/types/enums.test.ts#enum-of-enums-4{ts:line-numbers} +<<< @/../../docs-snippets2/src/types/enums.ts#enums-7{ts:line-numbers} ## Errors @@ -52,16 +52,16 @@ While working with enums, you may run into the following issues: Thrown when the type being passed to the enum does not match that expected by it. -<<< @/../../docs-snippets/src/guide/types/enums.test.ts#enum-error-mismatch-type{ts:line-numbers} +<<< @/../../docs-snippets2/src/types/enums.ts#enums-8{ts:line-numbers} ### Using an invalid enum value Thrown when the parameter passed is not an expected enum value. -<<< @/../../docs-snippets/src/guide/types/enums.test.ts#enum-error-value-mismatch{ts:line-numbers} +<<< @/../../docs-snippets2/src/types/enums.ts#enums-9{ts:line-numbers} ### Using an invalid enum case key Thrown when the passed enum case is not an expected enum case value. -<<< @/../../docs-snippets/src/guide/types/enums.test.ts#enum-error-case-key-mismatch{ts:line-numbers} +<<< @/../../docs-snippets2/src/types/enums.ts#enums-10{ts:line-numbers}