From d58ad8c96c5d6e1a02f5d3f11c110366099f99bb Mon Sep 17 00:00:00 2001 From: Damir Shamanaev Date: Mon, 21 Oct 2024 18:09:56 +0300 Subject: [PATCH] follow up, whoopsie --- book/src/move-basics/comments.md | 10 +- book/src/move-basics/constants.md | 18 +-- book/src/move-basics/function.md | 4 +- book/src/move-basics/importing-modules.md | 12 +- book/src/move-basics/module.md | 20 ++- book/src/move-basics/ownership-and-scope.md | 126 +++++++++--------- book/src/move-basics/references.md | 1 - book/src/move-basics/struct-methods.md | 4 +- book/src/move-basics/testing.md | 99 +++++++------- book/src/move-basics/visibility.md | 64 ++++----- book/src/programmability/capability.md | 6 +- book/src/programmability/collections.md | 6 +- book/src/programmability/events.md | 20 +-- .../src/programmability/module-initializer.md | 2 +- book/src/programmability/witness-pattern.md | 32 ++--- book/src/your-first-move/hello-world.md | 55 ++++---- theme/highlight.js | 2 +- 17 files changed, 242 insertions(+), 239 deletions(-) diff --git a/book/src/move-basics/comments.md b/book/src/move-basics/comments.md index 5f7cabe5..64b76cd4 100644 --- a/book/src/move-basics/comments.md +++ b/book/src/move-basics/comments.md @@ -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 @@ -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 @@ -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}} ``` diff --git a/book/src/move-basics/constants.md b/book/src/move-basics/constants.md index f00e3bd6..b9eba314 100644 --- a/book/src/move-basics/constants.md +++ b/book/src/move-basics/constants.md @@ -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 @@ -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 @@ -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; } ``` @@ -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 diff --git a/book/src/move-basics/function.md b/book/src/move-basics/function.md index 08c03f4c..66ef63bc 100644 --- a/book/src/move-basics/function.md +++ b/book/src/move-basics/function.md @@ -7,7 +7,7 @@ the `fun` keyword at the module level. Just like any other module member, by def and can only be accessed from within the module. ```move -{{#include ../../../packages/samples/sources/move-basics/function.move:math}} +{{#include ../../../packages/samples/sources/move-basics/function_math.move:math}} ``` In this example, we define a function `add` that takes two arguments of type `u64` and returns their @@ -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 diff --git a/book/src/move-basics/importing-modules.md b/book/src/move-basics/importing-modules.md index 98695431..f20cbae3 100644 --- a/book/src/move-basics/importing-modules.md +++ b/book/src/move-basics/importing-modules.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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}} ``` diff --git a/book/src/move-basics/module.md b/book/src/move-basics/module.md index ce7bc4a7..e9bd0f19 100644 --- a/book/src/move-basics/module.md +++ b/book/src/move-basics/module.md @@ -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. +> 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: @@ -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}} ``` diff --git a/book/src/move-basics/ownership-and-scope.md b/book/src/move-basics/ownership-and-scope.md index f11c4b18..94ce17af 100644 --- a/book/src/move-basics/ownership-and-scope.md +++ b/book/src/move-basics/ownership-and-scope.md @@ -20,21 +20,21 @@ scope and executes every expression and statement. Once the function scope end, defined in it are dropped or deallocated. ```move -module book::ownership { - public fun owner() { - let a = 1; // a is owned by the `owner` function - } // a is dropped here - - public fun other() { - let b = 2; // b is owned by the `other` function - } // b is dropped here - - #[test] - fun test_owner() { - owner(); - other(); - // a & b is not valid here - } +module book::ownership; + +public fun owner() { + let a = 1; // a is owned by the `owner` function +} // a is dropped here + +public fun other() { + let b = 2; // b is owned by the `other` function +} // b is dropped here + +#[test] +fun test_owner() { + owner(); + other(); + // a & b is not valid here } ``` @@ -48,18 +48,18 @@ If we changed the `owner` function to return the variable `a`, then the ownershi transferred to the caller of the function. ```move -module book::ownership { - public fun owner(): u8 { - let a = 1; // a defined here - a // scope ends, a is returned - } - - #[test] - fun test_owner() { - let a = owner(); - // a is valid here - } // a is dropped here +module book::ownership; + +public fun owner(): u8 { + let a = 1; // a defined here + a // scope ends, a is returned } + +#[test] +fun test_owner() { + let a = owner(); + // a is valid here +} // a is dropped here ``` ## Passing by Value @@ -69,22 +69,22 @@ transferred to this function. When performing this operation, we _move_ the valu another. This is also called _move semantics_. ```move -module book::ownership { - public fun owner(): u8 { - let a = 10; - a - } // a is returned - - public fun take_ownership(v: u8) { - // v is owned by `take_ownership` - } // v is dropped here - - #[test] - fun test_owner() { - let a = owner(); - take_ownership(a); - // a is not valid here - } +module book::ownership; + +public fun owner(): u8 { + let a = 10; + a +} // a is returned + +public fun take_ownership(v: u8) { + // v is owned by `take_ownership` +} // v is dropped here + +#[test] +fun test_owner() { + let a = owner(); + take_ownership(a); + // a is not valid here } ``` @@ -95,34 +95,34 @@ sequence of statements and expressions, and it has its own scope. Variables defi owned by this block, and when the block ends, the variables are dropped. ```move -module book::ownership { - public fun owner() { - let a = 1; // a is owned by the `owner` function's scope +module book::ownership; + +public fun owner() { + let a = 1; // a is owned by the `owner` function's scope + { + let b = 2; // b is owned by the block { - let b = 2; // b is owned by the block - { - let c = 3; // c is owned by the block - }; // c is dropped here - }; // b is dropped here - // a = b; // error: b is not valid here - // a = c; // error: c is not valid here - } // a is dropped here -} + let c = 3; // c is owned by the block + }; // c is dropped here + }; // b is dropped here + // a = b; // error: b is not valid here + // a = c; // error: c is not valid here +} // a is dropped here ``` However, shall we use the return value of a block, the ownership of the variable is transferred to the caller of the block. ```move -module book::ownership { - public fun owner(): u8 { - let a = 1; // a is owned by the `owner` function's scope - let b = { - let c = 2; // c is owned by the block - c // c is returned - }; // c is dropped here - a + b // both a and b are valid here - } +module book::ownership; + +public fun owner(): u8 { + let a = 1; // a is owned by the `owner` function's scope + let b = { + let c = 2; // c is owned by the block + c // c is returned + }; // c is dropped here + a + b // both a and b are valid here } ``` diff --git a/book/src/move-basics/references.md b/book/src/move-basics/references.md index 72b27c24..66ef6aa3 100644 --- a/book/src/move-basics/references.md +++ b/book/src/move-basics/references.md @@ -42,7 +42,6 @@ module book::metro_pass { {{#include ../../../packages/samples/sources/move-basics/references.move:header}} {{#include ../../../packages/samples/sources/move-basics/references.move:new}} -} ``` diff --git a/book/src/move-basics/struct-methods.md b/book/src/move-basics/struct-methods.md index f596314f..e35fee8f 100644 --- a/book/src/move-basics/struct-methods.md +++ b/book/src/move-basics/struct-methods.md @@ -41,7 +41,7 @@ with `hero_` and `villain_` respectively. However, we can create aliases for the they can be called on the instances of the structs without the prefix. ```move -{{#include ../../../packages/samples/sources/move-basics/struct-methods.move:hero_and_villain}} +{{#include ../../../packages/samples/sources/move-basics/struct-methods-2.move:hero_and_villain}} ``` As you can see, in the test function, we called the `health` method on the instances of `Hero` and @@ -57,7 +57,7 @@ associate it with the `Hero` struct. It will allow serializing the `Hero` struct bytes. ```move -{{#include ../../../packages/samples/sources/move-basics/struct-methods.move:hero_to_bytes}} +{{#include ../../../packages/samples/sources/move-basics/struct-methods-3.move:hero_to_bytes}} ``` ## Further reading diff --git a/book/src/move-basics/testing.md b/book/src/move-basics/testing.md index a66df80c..b49aa1ab 100644 --- a/book/src/move-basics/testing.md +++ b/book/src/move-basics/testing.md @@ -12,21 +12,21 @@ functions are regular functions, but they must take no arguments and have no ret are excluded from the bytecode, and are never published. ```move -module book::testing { - // Test attribute is placed before the `fun` keyword. Can be both above or - // right before the `fun` keyword: `#[test] fun my_test() { ... }` - // The name of the test would be `book::testing::simple_test`. - #[test] - fun simple_test() { - let sum = 2 + 2; - assert!(sum == 4, 1); - } - - // The name of the test would be `book::testing::more_advanced_test`. - #[test] fun more_advanced_test() { - let sum = 2 + 2 + 2; - assert!(sum == 4, 1); - } +module book::testing; + +// Test attribute is placed before the `fun` keyword. Can be both above or +// right before the `fun` keyword: `#[test] fun my_test() { ... }` +// The name of the test would be `book::testing::simple_test`. +#[test] +fun simple_test() { + let sum = 2 + 2; + assert!(sum == 4); +} + +// The name of the test would be `book::testing::more_advanced_test`. +#[test] fun more_advanced_test() { + let sum = 2 + 2 + 2; + assert!(sum == 4); } ``` @@ -60,21 +60,20 @@ fails. If the test fails with a different abort code, the test will fail. If the abort, the test will also fail. ```move -module book::testing_failure { +module book::testing_failure; - const EInvalidArgument: u64 = 1; +const EInvalidArgument: u64 = 1; - #[test] - #[expected_failure(abort_code = 0)] - fun test_fail() { - abort 0 // aborts with 0 - } +#[test] +#[expected_failure(abort_code = 0)] +fun test_fail() { + abort 0 // aborts with 0 +} - // attributes can be grouped together - #[test, expected_failure(abort_code = EInvalidArgument)] - fun test_fail_1() { - abort 1 // aborts with 1 - } +// attributes can be grouped together +#[test, expected_failure(abort_code = EInvalidArgument)] +fun test_fail_1() { + abort 1 // aborts with 1 } ``` @@ -89,29 +88,29 @@ important to remember that these functions should not be included in the final p where the `#[test_only]` attribute comes in handy. ```move -module book::testing { - // Public function which uses the `secret` function. - public fun multiply_by_secret(x: u64): u64 { - x * secret() - } - - /// Private function which is not available to the public. - fun secret(): u64 { 100 } - - #[test_only] - /// This function is only available for testing purposes in tests and other - /// test-only functions. Mind the visibility - for `#[test_only]` it is - /// common to use `public` visibility. - public fun secret_for_testing(): u64 { - secret() - } - - #[test] - // In the test environment we have access to the `secret_for_testing` function. - fun test_multiply_by_secret() { - let expected = secret_for_testing() * 2; - assert!(multiply_by_secret(2) == expected, 1); - } +module book::testing; + +// Public function which uses the `secret` function. +public fun multiply_by_secret(x: u64): u64 { + x * secret() +} + +/// Private function which is not available to the public. +fun secret(): u64 { 100 } + +#[test_only] +/// This function is only available for testing purposes in tests and other +/// test-only functions. Mind the visibility - for `#[test_only]` it is +/// common to use `public` visibility. +public fun secret_for_testing(): u64 { + secret() +} + +#[test] +// In the test environment we have access to the `secret_for_testing` function. +fun test_multiply_by_secret() { + let expected = secret_for_testing() * 2; + assert!(multiply_by_secret(2) == expected); } ``` diff --git a/book/src/move-basics/visibility.md b/book/src/move-basics/visibility.md index 8febf7fc..b01e69f9 100644 --- a/book/src/move-basics/visibility.md +++ b/book/src/move-basics/visibility.md @@ -12,14 +12,14 @@ A function or a struct defined in a module which has no visibility modifier is _ module. It can't be called from other modules. ```move -module book::internal_visibility { - // This function can be called from other functions in the same module - fun internal() { /* ... */ } - - // Same module -> can call internal() - fun call_internal() { - internal(); - } +module book::internal_visibility; + +// This function can be called from other functions in the same module +fun internal() { /* ... */ } + +// Same module -> can call internal() +fun call_internal() { + internal(); } ``` @@ -28,13 +28,13 @@ module book::internal_visibility { ```move -module book::try_calling_internal { - use book::internal_visibility; +module book::try_calling_internal; + +use book::internal_visibility; - // Different module -> can't call internal() - fun try_calling_internal() { - internal_visibility::internal(); - } +// Different module -> can't call internal() +fun try_calling_internal() { + internal_visibility::internal(); } ``` @@ -44,22 +44,22 @@ A struct or a function can be made _public_ by adding the `public` keyword befor `struct` keyword. ```move -module book::public_visibility { - // This function can be called from other modules - public fun public() { /* ... */ } -} +module book::public_visibility; + +// This function can be called from other modules +public fun public() { /* ... */ } ``` A public function can be imported and called from other modules. The following code will compile: ```move module book::try_calling_public { - use book::public_visibility; - // Different module -> can call public() - fun try_calling_public() { - public_visibility::public(); - } +use book::public_visibility; + +// Different module -> can call public() +fun try_calling_public() { + public_visibility::public(); } ``` @@ -69,20 +69,20 @@ Move 2024 introduces the _package visibility_ modifier. A function with _package called from any module within the same package. It can't be called from other packages. ```move -module book::package_visibility { - public(package) fun package_only() { /* ... */ } -} +module book::package_visibility; + +public(package) fun package_only() { /* ... */ } ``` A package function can be called from any module within the same package: ```move -module book::try_calling_package { - use book::package_visibility; +module book::try_calling_package; + +use book::package_visibility; - // Same package `book` -> can call package_only() - fun try_calling_package() { - package_visibility::package_only(); - } +// Same package `book` -> can call package_only() +fun try_calling_package() { + package_visibility::package_only(); } ``` diff --git a/book/src/programmability/capability.md b/book/src/programmability/capability.md index 1e93be4b..8c993937 100644 --- a/book/src/programmability/capability.md +++ b/book/src/programmability/capability.md @@ -26,7 +26,7 @@ A very common practice is to create a single `AdminCap` object on package publis application can have a setup phase where the admin account prepares the state of the application. ```move -{{#include ../../../packages/samples/sources/programmability/capability.move:admin_cap}} +{{#include ../../../packages/samples/sources/programmability/capability-2.move:admin_cap}} ``` ## Address check vs Capability @@ -40,13 +40,13 @@ Let's look at how the `new` function that creates a user would look like if it w check: ```move -{{#include ../../../packages/samples/sources/programmability/capability.move:with_address}} +{{#include ../../../packages/samples/sources/programmability/capability-3.move:with_address}} ``` And now, let's see how the same function would look like with the capability: ```move -{{#include ../../../packages/samples/sources/programmability/capability.move:with_capability}} +{{#include ../../../packages/samples/sources/programmability/capability-4.move:with_capability}} ``` Using capabilities has several advantages over the address check: diff --git a/book/src/programmability/collections.md b/book/src/programmability/collections.md index 34d26c4e..20979710 100644 --- a/book/src/programmability/collections.md +++ b/book/src/programmability/collections.md @@ -23,7 +23,7 @@ does not allow duplicate items. This makes it useful for storing a collection of as a list of unique IDs or addresses. ```move -{{#include ../../../packages/samples/sources/programmability/collections.move:vec_set}} +{{#include ../../../packages/samples/sources/programmability/collections-2.move:vec_set}} ``` VecSet will fail on attempt to insert an item that already exists in the set. @@ -40,7 +40,7 @@ to insert a key-value pair with a key that already exists in the map, the old va with the new value. ```move -{{#include ../../../packages/samples/sources/programmability/collections.move:vec_map}} +{{#include ../../../packages/samples/sources/programmability/collections-3.move:vec_map}} ``` ## Limitations @@ -59,7 +59,7 @@ results. > 'sui::vec_set::VecSet' may yield unexpected result_ ```move -{{#include ../../../packages/samples/sources/programmability/collections.move:vec_set_comparison}} +{{#include ../../../packages/samples/sources/programmability/collections-4.move:vec_set_comparison}} ``` In the example above, the comparison will fail because the order of insertion is not guaranteed, and diff --git a/book/src/programmability/events.md b/book/src/programmability/events.md index d2a78d36..68260d17 100644 --- a/book/src/programmability/events.md +++ b/book/src/programmability/events.md @@ -11,16 +11,16 @@ on-chain. Events are emitted by the `sui::event` module located in the ```move // File: sui-framework/sources/event.move -module sui::event { - /// Emit a custom Move event, sending the data offchain. - /// - /// Used for creating custom indexes and tracking onchain - /// activity in a way that suits a specific application the most. - /// - /// The type `T` is the main way to index the event, and can contain - /// phantom parameters, eg `emit(MyEvent)`. - public native fun emit(event: T); -} +module sui::event; + +/// Emit a custom Move event, sending the data offchain. +/// +/// Used for creating custom indexes and tracking onchain +/// activity in a way that suits a specific application the most. +/// +/// The type `T` is the main way to index the event, and can contain +/// phantom parameters, eg `emit(MyEvent)`. +public native fun emit(event: T); ``` ## Emitting Events diff --git a/book/src/programmability/module-initializer.md b/book/src/programmability/module-initializer.md index 1ce6c2ce..76da5037 100644 --- a/book/src/programmability/module-initializer.md +++ b/book/src/programmability/module-initializer.md @@ -16,7 +16,7 @@ function will automatically be called when the module is published. In the same package, another module can have its own `init` function, encapsulating distinct logic. ```move -{{#include ../../../packages/samples/sources/programmability/module-initializer.move:other}} +{{#include ../../../packages/samples/sources/programmability/module-initializer-2.move:other}} ``` ## `init` features diff --git a/book/src/programmability/witness-pattern.md b/book/src/programmability/witness-pattern.md index 30475ebf..a135d69f 100644 --- a/book/src/programmability/witness-pattern.md +++ b/book/src/programmability/witness-pattern.md @@ -19,14 +19,14 @@ to create a `Instance` instance. > the [Drop](./../move-basics/drop-ability.md) ability for the type. ```move -module book::witness { - /// A struct that requires a witness to be created. - public struct Instance { t: T } - - /// Create a new instance of `Instance` with the provided T. - public fun new(witness: T): Instance { - Instance { t: witness } - } +module book::witness; + +/// A struct that requires a witness to be created. +public struct Instance { t: T } + +/// Create a new instance of `Instance` with the provided T. +public fun new(witness: T): Instance { + Instance { t: witness } } ``` @@ -35,16 +35,16 @@ type `T`. This is a basic example of the witness pattern in Move. A module provi has a matching implementation, like the module `book::witness_source` below: ```move -module book::witness_source { - use book::witness::{Self, Instance}; +module book::witness_source; + +use book::witness::{Self, Instance}; - /// A struct used as a witness. - public struct W {} +/// A struct used as a witness. +public struct W {} - /// Create a new instance of `Instance`. - public fun new_instance(): Instance { - witness::new(W {}) - } +/// Create a new instance of `Instance`. +public fun new_instance(): Instance { + witness::new(W {}) } ``` diff --git a/book/src/your-first-move/hello-world.md b/book/src/your-first-move/hello-world.md index eb3bbff6..5ed10068 100644 --- a/book/src/your-first-move/hello-world.md +++ b/book/src/your-first-move/hello-world.md @@ -83,9 +83,7 @@ _hello_world.move_ and the Move CLI has already placed commented out code inside ```move /* /// Module: hello_world -module hello_world::hello_world { - -} +module hello_world::hello_world; */ ``` @@ -116,21 +114,20 @@ The _hello_world_tests.move_ file contains a commented out test module template: ```move /* #[test_only] -module hello_world::hello_world_tests { - // uncomment this line to import the module - // use hello_world::hello_world; +module hello_world::hello_world_tests; +// uncomment this line to import the module +// use hello_world::hello_world; - const ENotImplemented: u64 = 0; +const ENotImplemented: u64 = 0; - #[test] - fun test_hello_world() { - // pass - } +#[test] +fun test_hello_world() { + // pass +} - #[test, expected_failure(abort_code = hello_world::hello_world_tests::ENotImplemented)] - fun test_hello_world_fail() { - abort ENotImplemented - } +#[test, expected_failure(abort_code = hello_world::hello_world_tests::ENotImplemented)] +fun test_hello_world_fail() { + abort ENotImplemented } */ ``` @@ -154,14 +151,14 @@ with the following: ```move /// The module `hello_world` under named address `hello_world`. /// The named address is set in the `Move.toml`. -module hello_world::hello_world { - // Imports the `String` type from the Standard Library - use std::string::String; - - /// Returns the "Hello, World!" as a `String`. - public fun hello_world(): String { - b"Hello, World!".to_string() - } +module hello_world::hello_world; + +// Imports the `String` type from the Standard Library +use std::string::String; + +/// Returns the "Hello, World!" as a `String`. +public fun hello_world(): String { + b"Hello, World!".to_string() } ``` @@ -203,13 +200,13 @@ Replace the contents of the `tests/hello_world_tests.move` with the following co ```move #[test_only] -module hello_world::hello_world_tests { - use hello_world::hello_world; +module hello_world::hello_world_tests; + +use hello_world::hello_world; - #[test] - fun test_hello_world() { - assert!(hello_world::hello_world() == b"Hello, World!".to_string(), 0); - } +#[test] +fun test_hello_world() { + assert!(hello_world::hello_world() == b"Hello, World!".to_string(), 0); } ``` diff --git a/theme/highlight.js b/theme/highlight.js index 0c23b73a..a63c3615 100644 --- a/theme/highlight.js +++ b/theme/highlight.js @@ -441,7 +441,7 @@ hljs.registerLanguage('move', function(hljs) { // module definition scope: 'module', begin: /\bmodule\b/, - end: /\{/, + end: /[;{]/, keywords: 'module', contains: [ BLOCK_COMMENT,