Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/src/before-we-begin/ide-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ features. Whatever IDE you choose, you'll need to use the terminal to run the

- [IntelliJ IDEA](https://www.jetbrains.com/idea/) is a commercial IDE from JetBrains.
- [Move Language Plugin](https://plugins.jetbrains.com/plugin/14721-move-language) provides a Move
language extension for IntelliJ IDEA by [Pontem Network](https://pontem.network/).
on Sui language extension for IntelliJ IDEA by [MoveFuns](https://movefuns.org/).

## Emacs

Expand Down
4 changes: 2 additions & 2 deletions book/src/move-basics/abilities-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ A struct without abilities cannot be discarded, or copied, or stored in the stor
struct a _Hot Potato_. It is a joke, but it is also a good way to remember that a struct without
abilities is like a hot potato - it can only be passed around and requires special handling. Hot
Potato is one of the most powerful patterns in Move, we go in detail about it in the
[Hot Potato](./../programmability/hot-potato.md) chapter.
[Hot Potato Pattern](./../programmability/hot-potato-pattern.md) chapter.

## Further reading

- [Type Abilities](/reference/type-abilities.html) in the Move Reference.
- [Type Abilities](/reference/abilities.html) in the Move Reference.
13 changes: 12 additions & 1 deletion book/src/move-basics/assert-and-abort.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ The code above will, of course, abort with abort code `1`.
The `assert!` macro is a built-in macro that can be used to assert a condition. If the condition is
false, the transaction will abort with the given abort code. The `assert!` macro is a convenient way
to abort a transaction if a condition is not met. The macro shortens the code otherwise written with
an `if` expression + `abort`. The `code` argument is required and has to be a `u64` value.
an `if` expression + `abort`. The `code` argument is optional, but has to be a `u64` value or an
`#[error]` (see below for more information).

```move
{{#include ../../../packages/samples/sources/move-basics/assert-and-abort.move:assert}}
Expand All @@ -63,6 +64,16 @@ code and make it easier to understand the abort scenarios.
{{#include ../../../packages/samples/sources/move-basics/assert-and-abort.move:error_const}}
```

## Error messages

Move 2024 introduces a special type of error constant, marked with the `#[error]` attribute. This
attribute allows the error constant to be of type `vector<u8>` and can be used to store an error
message.

```move
{{#include ../../../packages/samples/sources/move-basics/assert-and-abort.move:error_attribute}}
```

## Further reading

- [Abort and Assert](/reference/abort-and-assert.html) in the Move Reference.
Expand Down
10 changes: 3 additions & 7 deletions book/src/move-basics/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ comment.

## Line comment

```Move
{{#include ../../../packages/samples/sources/move-basics/comments.move:line}}
```

You can use double slash `//` to comment out the rest of the line. Everything after `//` will be
ignored by the compiler.

```Move
{{#include ../../../packages/samples/sources/move-basics/comments.move:line_2}}
{{#include ../../../packages/samples/sources/move-basics/comments-line.move:main}}
```

## Block comment
Expand All @@ -38,7 +34,7 @@ Everything between `/*` and `*/` will be ignored by the compiler. You can use bl
comment out a single line or multiple lines. You can even use them to comment out a part of a line.

```Move
{{#include ../../../packages/samples/sources/move-basics/comments.move:block}}
{{#include ../../../packages/samples/sources/move-basics/comments-block.move:main}}
```

This example is a bit extreme, but it shows how you can use block comments to comment out a part of
Expand All @@ -51,7 +47,7 @@ They are similar to block comments, but they start with three slashes `///` and
the definition of the item they document.

```Move
{{#include ../../../packages/samples/sources/move-basics/comments.move:doc}}
{{#include ../../../packages/samples/sources/move-basics/comments-doc.move:main}}
```

<!-- TODO: docgen, which members are in the documentation -->
18 changes: 9 additions & 9 deletions book/src/move-basics/constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ price for a product, you might define a constant for it. Constants are stored in
bytecode, and each time they are used, the value is copied.

```move
{{#include ../../../packages/samples/sources/move-basics/constants.move:shop_price}}
{{#include ../../../packages/samples/sources/move-basics/constants-shop-price.move:shop_price}}
```

## Naming Convention
Expand All @@ -35,7 +35,7 @@ It's a way to make constants stand out from other identifiers in the code. One e
[error constants](./assert-and-abort.md#assert-and-abort), which are written in ECamelCase.

```move
{{#include ../../../packages/samples/sources/move-basics/constants.move:naming}}
{{#include ../../../packages/samples/sources/move-basics/constants-naming.move:naming}}
```

## Constants are Immutable
Expand All @@ -44,13 +44,13 @@ Constants can't be changed and assigned new values. They are part of the package
inherently immutable.

```move
module book::immutable_constants {
const ITEM_PRICE: u64 = 100;
module book::immutable_constants;

// emits an error
fun change_price() {
ITEM_PRICE = 200;
}
const ITEM_PRICE: u64 = 100;

// emits an error
fun change_price() {
ITEM_PRICE = 200;
}
```

Expand All @@ -61,7 +61,7 @@ codebase. But due to constants being private to the module, they can't be access
modules. One way to solve this is to define a "config" module that exports the constants.

```move
{{#include ../../../packages/samples/sources/move-basics/constants.move:config}}
{{#include ../../../packages/samples/sources/move-basics/constants-config.move:config}}
```

This way other modules can import and read the constants, and the update process is simplified. If
Expand Down
2 changes: 1 addition & 1 deletion book/src/move-basics/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ control flow statements (explained in detail below):
code
- [`loop` and `while` loops](#repeating-statements-with-loops) - repeating a block of code
- [`break` and `continue` statements](#exiting-a-loop-early) - exiting a loop early
- [`return`](#return) statement - exiting a function early
- [`return`](#early-return) statement - exiting a function early

## Conditional Statements

Expand Down
2 changes: 1 addition & 1 deletion book/src/move-basics/copy-ability.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ All of the types defined in the standard library have the `copy` ability as well

## Further reading

- [Type Abilities](/reference/type-abilities.html) in the Move Reference.
- [Type Abilities](/reference/abilities.html) in the Move Reference.
4 changes: 2 additions & 2 deletions book/src/move-basics/drop-ability.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ properly handled and not ignored.

A struct with a single `drop` ability is called a _Witness_. We explain the concept of a _Witness_
in the
[Witness and Abstract Implementation](./../programmability/witness-and-abstract-implementation.md)
[Witness and Abstract Implementation](./../programmability/witness-pattern.md)
section.

## Types with the `drop` Ability
Expand All @@ -76,4 +76,4 @@ All of the types defined in the standard library have the `drop` ability as well

## Further reading

- [Type Abilities](/reference/type-abilities.html) in the Move Reference.
- [Type Abilities](/reference/abilities.html) in the Move Reference.
2 changes: 1 addition & 1 deletion book/src/move-basics/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function called `add` in the `math` module in the `book` package, the path to it
`book::math::add`, or, if the module is imported, `math::add`.

```move
{{#include ../../../packages/samples/sources/move-basics/function.move:use_math}}
{{#include ../../../packages/samples/sources/move-basics/function_use.move:use_math}}
```

## Multiple return values
Expand Down
12 changes: 6 additions & 6 deletions book/src/move-basics/importing-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Another module defined in the same package can import the first module using the

```move
// File: sources/module_two.move
{{#include ../../../packages/samples/sources/move-basics/importing-modules.move:module_two}}
{{#include ../../../packages/samples/sources/move-basics/importing-modules-two.move:module_two}}
```

## Importing Members
Expand All @@ -48,7 +48,7 @@ function or a single type from a module. The syntax is the same as for importing
add the member name after the module path.

```move
{{#include ../../../packages/samples/sources/move-basics/importing-modules.move:members}}
{{#include ../../../packages/samples/sources/move-basics/importing-modules-members.move:members}}
```

## Grouping Imports
Expand All @@ -58,7 +58,7 @@ when you need to import multiple members from the same module. Move allows group
same module and from the same package.

```move
{{#include ../../../packages/samples/sources/move-basics/importing-modules.move:grouped}}
{{#include ../../../packages/samples/sources/move-basics/importing-modules-grouped.move:grouped}}
```

Single function imports are less common in Move, since the function names can overlap and cause
Expand All @@ -69,7 +69,7 @@ To import members and the module itself in the group import, you can use the `Se
`Self` keyword refers to the module itself and can be used to import the module and its members.

```move
{{#include ../../../packages/samples/sources/move-basics/importing-modules.move:self}}
{{#include ../../../packages/samples/sources/move-basics/importing-modules-self.move:self}}
```

## Resolving Name Conflicts
Expand All @@ -81,7 +81,7 @@ in different packages. To resolve the conflict and avoid ambiguity, Move offers
rename the imported member.

```move
{{#include ../../../packages/samples/sources/move-basics/importing-modules.move:conflict}}
{{#include ../../../packages/samples/sources/move-basics/importing-modules-conflict-resolution.move:conflict}}
```

## Adding an External Dependency
Expand Down Expand Up @@ -116,5 +116,5 @@ To import a module from another package, you use the `use` keyword followed by t
module path consists of the package address (or alias) and the module name separated by `::`.

```move
{{#include ../../../packages/samples/sources/move-basics/importing-modules.move:external}}
{{#include ../../../packages/samples/sources/move-basics/importing-modules-external.move:external}}
```
22 changes: 17 additions & 5 deletions book/src/move-basics/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ learn how to define a module, how to declare its members and how to access them

## Module declaration

Modules are declared using the `module` keyword followed by the package address, module name and the
module body inside the curly braces `{}`. The module name should be in `snake_case` - all lowercase
letters with underscores between words. Modules names must be unique in the package.
Modules are declared using the `module` keyword followed by the package address, module name,
semicolon, and the module body. The module name should be in `snake_case` - all lowercase letters
with underscores between words. Modules names must be unique in the package.

Usually, a single file in the `sources/` folder contains a single module. The file name should match
the module name - for example, a `donut_shop` module should be stored in the `donut_shop.move` file.
You can read more about coding conventions in the
[Coding Conventions](../special-topics/coding-conventions.md) section.
[Coding Conventions](../guides/coding-conventions.md) section.

> If you need to declare more than one module in a file, you must use [Module Block](#module-block).

```Move
{{#include ../../../packages/samples/sources/move-basics/module.move:module}}
{{#include ../../../packages/samples/sources/move-basics/module-label.move:module}}
```

Structs, functions, constants and imports all part of the module:
Expand Down Expand Up @@ -63,6 +65,16 @@ book = "0x0"
Module members are declared inside the module body. To illustrate that, let's define a simple module
with a struct, a function and a constant:

```Move
{{#include ../../../packages/samples/sources/move-basics/module-members.move:members}}
```

## Module block

Pre-2024 edition of Move required _module block_ - the contents of the module need to be surrounded
by curly braces `{}`. The main reason to use block and not _label_ is if you need to define more
than one module in a file.

```Move
{{#include ../../../packages/samples/sources/move-basics/module.move:members}}
```
Expand Down
2 changes: 0 additions & 2 deletions book/src/move-basics/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Option is a type that represents an optional value which may or may not exist. T
in Move is borrowed from Rust, and it is a very useful primitive in Move. `Option` is defined in the
[Standard Library](./standard-library.md), and is defined as follows:

File: move-stdlib/source/option.move

```move
// File: move-stdlib/source/option.move
/// Abstraction of a value that may or may not be present.
Expand Down
Loading