Skip to content

Commit

Permalink
fix(docs): fix struct docs (#5197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Electron authored Feb 4, 2025
1 parent 2e6aa88 commit 5d4e795
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ assets and resources, and inability to copy is a key element of the resource mod

However, Move type system allows you to define custom types with the _copy_ ability.

```move file=<rootDir>/docs/examples/move/move-overview/copy-ability.move#L8
```move file=<rootDir>/docs/examples/move/move-overview/copy-ability.move#L9
```

In the example above, we define a custom type `Copyable` with the _copy_ ability. This means that
instances of `Copyable` can be copied, both implicitly and explicitly.

```move file=<rootDir>/docs/examples/move/move-overview/copy-ability.move#L13-L20
```move file=<rootDir>/docs/examples/move/move-overview/copy-ability.move#L15-L21
```

In the example above, `a` is copied to `b` implicitly, and then explicitly copied to `c` using the
Expand All @@ -36,7 +36,7 @@ _copy_ ability, very likely that it should have `drop` too. This is because the
required to clean up the resources when the instance is no longer needed. If a type has only _copy_,
then managing its instances gets more complicated, as the values cannot be ignored.

```move file=<rootDir>/docs/examples/move/move-overview/copy-ability.move#L25
```move file=<rootDir>/docs/examples/move/move-overview/copy-ability.move#L26
```

All of the primitive types in Move behave as if they have the _copy_ and _drop_ abilities. This
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct without the `drop` ability is not allowed to be ignored. This is a safety
language, which ensures that all assets are properly handled. An attempt to ignore a struct without
the `drop` ability will result in a compilation error.

```move file=<rootDir>/docs/examples/move/move-overview/drop-ability.move#L5-L25
```move file=<rootDir>/docs/examples/move/move-overview/drop-ability.move#L6-L26
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ naturally became the defining ability for the object.
## Object Definition

A struct with the `key` ability is considered an object and can be used in the storage functions.
The Sui Verifier will require the first field of the struct to be named `id` and have the type
The IOTA Verifier will require the first field of the struct to be named `id` and have the type
`UID`.

```move
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ any type, including other structs.
Move does not support recursive structs, meaning a struct cannot contain itself as a field.
:::

```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L10-L28
```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L11-L29
```


Expand All @@ -49,15 +49,15 @@ We described how struct _definition_ works. Now let's see how to initialize a st
struct can be initialized using the `struct_name { field1: value1, field2: value2, ... }` syntax.
The fields can be initialized in any order, and all of the fields must be set.

```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L34-L36
```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L35-L37
```

In the example above, we create an instance of the `Artist` struct and set the `name` field to a
string "The Beatles".

To access the fields of a struct, you can use the `.` operator followed by the field name.

```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L40-L50
```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L41-L51
```

Only module defining the struct can access its fields (both mutably and immutably). So the above
Expand All @@ -70,13 +70,13 @@ Structs are non-discardable by default, meaning that the initiated struct value
stored or _unpacked_. Unpacking a struct means deconstructing it into its fields. This is done using
the `let` keyword followed by the struct name and the field names.

```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L54-L56
```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L55-L57
```

In the example above we unpack the `Artist` struct and create a new variable `name` with the value
of the `name` field. Because the variable is not used, the compiler will raise a warning. To
suppress the warning, you can use the underscore `_` to indicate that the variable is intentionally
unused.

```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L64-L65
```move file=<rootDir>/docs/examples/move/move-overview/struct.move#L65-L66
```
8 changes: 0 additions & 8 deletions docs/examples/move/ctf/challenge_7/package.json

This file was deleted.

0 comments on commit 5d4e795

Please sign in to comment.