From 4fb55e6e2b46bc534b8cc57c82b9172786569f10 Mon Sep 17 00:00:00 2001 From: Damir Shamanaev Date: Fri, 22 Mar 2024 21:57:37 +0300 Subject: [PATCH] fingers crossed --- _.github/workflows/docs.yml | 34 +++++++++++++++++ _.github/workflows/main.yml | 4 +- hello/Move.toml | 38 +++++++++++++++++++ hello/sources/hello.move | 6 +++ hello/tests/hello_tests.move | 21 ++++++++++ samples/Move.toml | 2 +- .../buffer.move | 0 .../sources/basic-syntax/control-flow.move | 2 - samples/sources/basic-syntax/module.move | 3 -- samples/sources/basic-syntax/struct.move | 2 - .../sources/basic-syntax/type-reflection.move | 2 - .../sources/programmability/collections.move | 2 - samples/sources/programmability/display.move | 2 - samples/sources/programmability/testing.move | 3 -- .../sources/your-first-move/hello_world.move | 6 +-- .../your-first-move/hello_world_debug.move | 6 +-- .../your-first-move/hello_world_docs.move | 6 +-- src/SUMMARY.md | 14 +++---- src/basic-syntax/struct-methods.md | 4 +- src/basic-syntax/struct.md | 10 +++++ src/basic-syntax/visibility.md | 34 ++--------------- 21 files changed, 132 insertions(+), 69 deletions(-) create mode 100644 _.github/workflows/docs.yml create mode 100644 hello/Move.toml create mode 100644 hello/sources/hello.move create mode 100644 hello/tests/hello_tests.move rename samples/{sources/complete-examples => examples}/buffer.move (100%) diff --git a/_.github/workflows/docs.yml b/_.github/workflows/docs.yml new file mode 100644 index 00000000..e7dd92f5 --- /dev/null +++ b/_.github/workflows/docs.yml @@ -0,0 +1,34 @@ +# Copy-pasta from MystenLabs/sui/.github/workflows/docs.yml + +name: Documentation + +on: + push: + branches: [ main, extensions ] + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + diff: + runs-on: [ubuntu-latest] + outputs: + isDoc: ${{ steps.diff.outputs.isDoc }} + isOldDoc: ${{ steps.diff.outputs.isOldDoc }} + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1 + - name: Detect Changes + uses: './.github/actions/diffs' + id: diff + + spelling: + name: Lint documentation + needs: diff + if: needs.diff.outputs.isDoc == 'true' + runs-on: [ubuntu-latest] + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1 + - name: Spell Check Docs + uses: crate-ci/typos@v1.16.11 + with: + files: ./src diff --git a/_.github/workflows/main.yml b/_.github/workflows/main.yml index a3e5542e..642ec8c3 100644 --- a/_.github/workflows/main.yml +++ b/_.github/workflows/main.yml @@ -2,7 +2,7 @@ name: Run mdbook and publish GitHub Pages on: push: - branches: ["book"] + branches: [] # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. @@ -25,4 +25,4 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./book - cname: sui.move.page + cname: move-book.com diff --git a/hello/Move.toml b/hello/Move.toml new file mode 100644 index 00000000..d41a7c60 --- /dev/null +++ b/hello/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "hello" + +# edition = "2024.alpha" # To use the Move 2024 edition, currently in alpha +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +hello = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/hello/sources/hello.move b/hello/sources/hello.move new file mode 100644 index 00000000..5e101298 --- /dev/null +++ b/hello/sources/hello.move @@ -0,0 +1,6 @@ +/* +/// Module: hello +module hello::hello { + +} +*/ diff --git a/hello/tests/hello_tests.move b/hello/tests/hello_tests.move new file mode 100644 index 00000000..a9167ca4 --- /dev/null +++ b/hello/tests/hello_tests.move @@ -0,0 +1,21 @@ +/* +#[test_only] +module hello::hello_tests { + // uncomment this line to import the module + // use hello::hello; + + const ENotImplemented: u64 = 0; + + #[test] + fun test_hello() { + // pass + } + + #[test, expected_failure(abort_code = hello::hello_tests::ENotImplemented)] + fun test_hello_fail() { + abort ENotImplemented + } +} +*/ + + diff --git a/samples/Move.toml b/samples/Move.toml index 18084a5a..3f4c2014 100644 --- a/samples/Move.toml +++ b/samples/Move.toml @@ -5,7 +5,7 @@ edition = "2024.alpha" [dependencies.Sui] git = "https://github.com/MystenLabs/sui.git" subdir = "crates/sui-framework/packages/sui-framework" -rev = "framework/testnet" +rev = "main" [addresses] book = "0x0" diff --git a/samples/sources/complete-examples/buffer.move b/samples/examples/buffer.move similarity index 100% rename from samples/sources/complete-examples/buffer.move rename to samples/examples/buffer.move diff --git a/samples/sources/basic-syntax/control-flow.move b/samples/sources/basic-syntax/control-flow.move index 3ef1e7a9..a583a0ee 100644 --- a/samples/sources/basic-syntax/control-flow.move +++ b/samples/sources/basic-syntax/control-flow.move @@ -5,8 +5,6 @@ module book::control_flow { // ANCHOR_END: module - use fun std::string::utf8 as vector.to_string; - // ANCHOR: if_condition #[test] fun test_if() { diff --git a/samples/sources/basic-syntax/module.move b/samples/sources/basic-syntax/module.move index b36bce57..5f4c8b2c 100644 --- a/samples/sources/basic-syntax/module.move +++ b/samples/sources/basic-syntax/module.move @@ -32,9 +32,6 @@ module book::my_module_with_members { // import use book::my_module; - // friend declaration - friend book::constants; - // a constant const CONST: u8 = 0; diff --git a/samples/sources/basic-syntax/struct.move b/samples/sources/basic-syntax/struct.move index e441d8c2..97a4da5d 100644 --- a/samples/sources/basic-syntax/struct.move +++ b/samples/sources/basic-syntax/struct.move @@ -5,8 +5,6 @@ module book::struct_syntax { use std::string::{Self, String}; - use fun std::string::utf8 as vector.to_string; - // ANCHOR: def /// A struct representing an artist. public struct Artist { diff --git a/samples/sources/basic-syntax/type-reflection.move b/samples/sources/basic-syntax/type-reflection.move index b2eec863..02cb7c93 100644 --- a/samples/sources/basic-syntax/type-reflection.move +++ b/samples/sources/basic-syntax/type-reflection.move @@ -7,8 +7,6 @@ module book::type_reflection { use std::ascii::String; use std::type_name::{Self, TypeName}; - use fun std::ascii::string as vector.to_ascii_string; - /// A function that returns the name of the type `T` and its module and address. public fun do_i_know_you(): (String, String, String) { let type_name: TypeName = type_name::get(); diff --git a/samples/sources/programmability/collections.move b/samples/sources/programmability/collections.move index 7ccd3c77..2e21e318 100644 --- a/samples/sources/programmability/collections.move +++ b/samples/sources/programmability/collections.move @@ -34,8 +34,6 @@ module book::collections { use std::string::String; use sui::vec_map::{Self, VecMap}; - use fun std::string::utf8 as vector.to_string; - public struct Metadata has drop { name: String, /// `VecMap` used in the struct definition diff --git a/samples/sources/programmability/display.move b/samples/sources/programmability/display.move index 1efe245d..d8344ef1 100644 --- a/samples/sources/programmability/display.move +++ b/samples/sources/programmability/display.move @@ -29,8 +29,6 @@ module book::arena { use sui::package; use sui::display; - use fun std::string::utf8 as vector.to_string; - /// The One Time Witness to claim the `Publisher` object. public struct ARENA has drop {} diff --git a/samples/sources/programmability/testing.move b/samples/sources/programmability/testing.move index 0c8a0390..8ad52241 100644 --- a/samples/sources/programmability/testing.move +++ b/samples/sources/programmability/testing.move @@ -4,9 +4,6 @@ module book::testing { use std::string::String; - use fun std::string::utf8 as vector.to_string; - - public struct Whoa { name: String } diff --git a/samples/sources/your-first-move/hello_world.move b/samples/sources/your-first-move/hello_world.move index 0ae57587..f852b18c 100644 --- a/samples/sources/your-first-move/hello_world.move +++ b/samples/sources/your-first-move/hello_world.move @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 module book::hello_world { - use std::string::{Self, String}; + use std::string::String; public fun hello_world(): String { - string::utf8(b"Hello, World!") + b"Hello, World!".to_string() } #[test] fun test_is_hello_world() { - let expected = string::utf8(b"Hello, World!"); + let expected = b"Hello, World!".to_string(); assert!(hello_world() == expected, 0) } } diff --git a/samples/sources/your-first-move/hello_world_debug.move b/samples/sources/your-first-move/hello_world_debug.move index 500fb6fe..00b85898 100644 --- a/samples/sources/your-first-move/hello_world_debug.move +++ b/samples/sources/your-first-move/hello_world_debug.move @@ -2,18 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 module book::hello_world_debug { - use std::string::{Self, String}; + use std::string::String; use std::debug; public fun hello_world(): String { - let result = string::utf8(b"Hello, World!"); + let result = b"Hello, World!".to_string(); debug::print(&result); result } #[test] fun test_is_hello_world() { - let expected = string::utf8(b"Hello, World!"); + let expected = b"Hello, World!".to_string(); let actual = hello_world(); assert!(actual == expected, 0) diff --git a/samples/sources/your-first-move/hello_world_docs.move b/samples/sources/your-first-move/hello_world_docs.move index 1317698f..d100e7ec 100644 --- a/samples/sources/your-first-move/hello_world_docs.move +++ b/samples/sources/your-first-move/hello_world_docs.move @@ -3,17 +3,17 @@ /// This module contains a function that returns a string "Hello, World!". module book::hello_world_docs { - use std::string::{Self, String}; + use std::string::String; /// As the name says: returns a string "Hello, World!". public fun hello_world(): String { - string::utf8(b"Hello, World!") + b"Hello, World!".to_string() } #[test] /// This is a test for the `hello_world` function. fun test_is_hello_world() { - let expected = string::utf8(b"Hello, World!"); + let expected = b"Hello, World!".to_string(); let actual = hello_world(); assert!(actual == expected, 0) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 615d870c..94554ba6 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -59,10 +59,14 @@ comparison to docs.sui.io - [Move 2024](before-we-begin/move-2024.md) - [Your First Move](your-first-move/README.md) - [Hello World!](your-first-move/hello-world.md) + - [Your First Sui App](./hello-sui/README.md) + - [Publishing]() + - [Hello Sui!](./hello-sui/hello-sui.md) + - [Using Objects](./hello-sui/module-structure.md) - [Adding Tests](your-first-move/adding-tests.md) - [Debugging](your-first-move/debugging.md) - [Generating Docs](your-first-move/generating-docs.md) - + - [Concepts](./concepts/README.md) - [What is a Package](./concepts/packages.md) @@ -73,12 +77,6 @@ comparison to docs.sui.io - [Account](./concepts/what-is-an-account.md) - [Transaction](./concepts/what-is-a-transaction.md) - [Object Model](./concepts/object-model.md) -- [Your First Sui App](./hello-sui/README.md) - - [Hello Sui!](./hello-sui/hello-sui.md) - - [Using Objects](./hello-sui/module-structure.md) - - [Testing]() - - [Publish and Interact]() - - [Ideas]() - [Syntax Basics](./basic-syntax/README.md) - [Module](./basic-syntax/module.md) - [Comments](./basic-syntax/comments.md) @@ -136,11 +134,11 @@ comparison to docs.sui.io - [Dynamic Fields](./programmability/dynamic-fields.md) - [Dynamic Collections]() - [Package Upgrades]() + - [One Time Witness]() - [Sui Framework](./programmability/sui-framework.md) - [Witness and Abstract Implementation](./programmability/witness-and-abstract-implementation.md) - [Events](./programmability/events.md) - [Display](./programmability/display.md) - - [One Time Witness]() - [Pattern: Request]() - [Pattern: Hot Potato]() - [Pattern: Object Capability]() diff --git a/src/basic-syntax/struct-methods.md b/src/basic-syntax/struct-methods.md index b595c4b9..e2b73460 100644 --- a/src/basic-syntax/struct-methods.md +++ b/src/basic-syntax/struct-methods.md @@ -19,10 +19,10 @@ For modules that define multiple structs and their methods, it is possible to de The syntax for aliases is: ```move // for local method association -use fun as .; +use fun function_path as Type.method_name; // exported alias -public use fun as .; +public use fun function_path as Type.method_name; ``` > Public aliases are only allowed for structs defined in the same module. If a struct is defined in another module, an alias can still be created but cannot be made public. diff --git a/src/basic-syntax/struct.md b/src/basic-syntax/struct.md index 35044cac..dc70b10f 100644 --- a/src/basic-syntax/struct.md +++ b/src/basic-syntax/struct.md @@ -36,6 +36,16 @@ To access the fields of a struct, you can use the `.` operator followed by the f Only module defining the struct can access its fields (both mutably and immutably). So the above code should be in the same module as the `Artist` struct. + + ## Unpacking a struct Structs are non-discardable by default, meaning that the initiated struct value must be used: either 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. diff --git a/src/basic-syntax/visibility.md b/src/basic-syntax/visibility.md index 930b3dc5..a0355891 100644 --- a/src/basic-syntax/visibility.md +++ b/src/basic-syntax/visibility.md @@ -1,10 +1,10 @@ # Visibility Modifiers -Every module member has a visibility. By default, all module members are *private* - meaning they are only accessible within the module they are defined in. However, you can add a visibility modifier to make a module member *public* - visible outside the module, or *friend* - visible in "friend" modules within the same package, or *entry* - can be called from a transaction but can't be called from other modules. +Every module member has a visibility. By default, all module members are *private* - meaning they are only accessible within the module they are defined in. However, you can add a visibility modifier to make a module member *public* - visible outside the module, or *public(package)* - visible in the modules within the same package, or *entry* - can be called from a transaction but can't be called from other modules. ## Internal Visibility -A function or a struct defined in a module which has no visibility modifier is *private*. +A function or a struct defined in a module which has no visibility modifier is *private* to the module. It can't be called from other modules. ```move module book::internal_visbility { @@ -18,7 +18,7 @@ module book::internal_visbility { } ``` -Move compiler won't allow this code to compile: + @@ -57,36 +57,8 @@ module book::try_calling_public { } ``` -## Friend Visibility - -Modules within the same package can be declared as *friends* to each other, and that enables the *friend visibility* modifier. A function with *friend visibility* can be called by friend modules. However, to the rest of the packages and non-friend modules, it is *private*. - -```move -module book::friend_visibility { - friend book::try_calling_friend; - - // This function can be called from friend modules - public(friend) fun friend_only() { /* ... */ } -} -``` - -A friend function can be called from a friend module, but not from a non-friend module: - -```move -module book::try_calling_friend { - use book::friend_visibility; - - // Same package, friend module -> can call friend() - fun try_calling_friend() { - friend_visibility::friend_only(); - } -} -``` - ## Package Visibility -> This feature of Move 2024 is not yet implemented. - Move 2024 introduces the *package visibility* modifier. A function with *package visibility* can be called from any module within the same package. It can't be called from other packages. ```move