-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
formatted + reference structure created
- Loading branch information
Showing
76 changed files
with
339 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# Assert and Abort | ||
|
||
|
||
|
||
<!-- | ||
Chapter: Basic Syntax | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
# Abilities: Copy | ||
|
||
In Move, the *copy* ability on a type indicates that the instance or the value of the type can be copied. While this behavior may feel very natural when working with numbers or other simple types, it is not the default for custom types in Move. This is because Move is designed to express digital assets and resources, and inability to copy is a key element of the resource model. | ||
In Move, the _copy_ ability on a type indicates that the instance or the value of the type can be copied. While this behavior may feel very natural when working with numbers or other simple types, it is not the default for custom types in Move. This is because Move is designed to express digital assets and resources, and inability to copy is a key element of the resource model. | ||
|
||
However, Move type system allows you to define custom types with the *copy* ability. | ||
However, Move type system allows you to define custom types with the _copy_ ability. | ||
|
||
```move | ||
{{#include ../../../packages/samples/sources/basic-syntax/copy-ability.move:copyable}} | ||
``` | ||
|
||
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. | ||
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 | ||
{{#include ../../../packages/samples/sources/basic-syntax/copy-ability.move:copyable_test}} | ||
``` | ||
|
||
In the example above, `a` is copied to `b` implicitly, and then explicitly copied to `c` using the dereference operator. If `Copyable` did not have the *copy* ability, the code would not compile, and the Move compiler would raise an error. | ||
In the example above, `a` is copied to `b` implicitly, and then explicitly copied to `c` using the dereference operator. If `Copyable` did not have the _copy_ ability, the code would not compile, and the Move compiler would raise an error. | ||
|
||
## Copying and Drop | ||
|
||
The `copy` ability is closely related to [`drop` ability](./drop-ability.md). If a type has the *copy* ability, very likely that it should have `drop` too. This is because the *drop* ability is 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. | ||
The `copy` ability is closely related to [`drop` ability](./drop-ability.md). If a type has the _copy_ ability, very likely that it should have `drop` too. This is because the _drop_ ability is 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 | ||
{{#include ../../../packages/samples/sources/basic-syntax/copy-ability.move:copy_drop}} | ||
``` | ||
|
||
All of the primitive types in Move behave as if they have the *copy* and *drop* abilities. This means that they can be copied and dropped, and the Move compiler will handle the memory management for them. | ||
All of the primitive types in Move behave as if they have the _copy_ and _drop_ abilities. This means that they can be copied and dropped, and the Move compiler will handle the memory management for them. |
Oops, something went wrong.