Skip to content

Commit

Permalink
fingers crossed
Browse files Browse the repository at this point in the history
  • Loading branch information
damirka committed Mar 22, 2024
1 parent b2e9f63 commit 4fb55e6
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 69 deletions.
34 changes: 34 additions & 0 deletions _.github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
files: ./src
4 changes: 2 additions & 2 deletions _.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,4 +25,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book
cname: sui.move.page
cname: move-book.com
38 changes: 38 additions & 0 deletions hello/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

[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"

6 changes: 6 additions & 0 deletions hello/sources/hello.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
/// Module: hello
module hello::hello {
}
*/
21 changes: 21 additions & 0 deletions hello/tests/hello_tests.move
Original file line number Diff line number Diff line change
@@ -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
}
}
*/


2 changes: 1 addition & 1 deletion samples/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
File renamed without changes.
2 changes: 0 additions & 2 deletions samples/sources/basic-syntax/control-flow.move
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 0 additions & 3 deletions samples/sources/basic-syntax/module.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions samples/sources/basic-syntax/struct.move
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions samples/sources/basic-syntax/type-reflection.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(): (String, String, String) {
let type_name: TypeName = type_name::get<T>();
Expand Down
2 changes: 0 additions & 2 deletions samples/sources/programmability/collections.move
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions samples/sources/programmability/display.move
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
3 changes: 0 additions & 3 deletions samples/sources/programmability/testing.move
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions samples/sources/your-first-move/hello_world.move
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions samples/sources/your-first-move/hello_world_debug.move
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions samples/sources/your-first-move/hello_world_docs.move
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<!-- - [Publishing]() -->
<!-- TODO: -->
<!-- - [Send a Transaction]() -->
- [Concepts](./concepts/README.md)
- [What is a Package](./concepts/packages.md)
Expand All @@ -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)
Expand Down Expand Up @@ -136,11 +134,11 @@ comparison to docs.sui.io
- [Dynamic Fields](./programmability/dynamic-fields.md)
- [Dynamic Collections]() <!-- (./programmability/dynamic-collections.md) -->
- [Package Upgrades]()<!-- (./programmability/package-upgrades.md) -->
- [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]()
Expand Down
4 changes: 2 additions & 2 deletions src/basic-syntax/struct-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <function_path> as <Type>.<method_name>;
use fun function_path as Type.method_name;
// exported alias
public use fun <function_path> as <Type>.<method_name>;
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.
Expand Down
10 changes: 10 additions & 0 deletions src/basic-syntax/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- ## Accessing Fields
Struct fields are private and can be accessed only by the module defining the struct. To access the fields of a struct, you can use the `.` operator followed by the field name.
```move
# anchor: access
{{#include ../../samples/sources/basic-syntax/struct.move:access}}
```
-->

## 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.
Expand Down
34 changes: 3 additions & 31 deletions src/basic-syntax/visibility.md
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,7 +18,7 @@ module book::internal_visbility {
}
```

Move compiler won't allow this code to compile:
<!-- Move compiler won't allow this code to compile: -->

<!-- TODO: add failure flag to example -->

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4fb55e6

Please sign in to comment.