Skip to content

Commit

Permalink
adds module label everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
damirka committed Oct 21, 2024
1 parent c46996a commit db007fd
Show file tree
Hide file tree
Showing 57 changed files with 1,127 additions and 1,135 deletions.
14 changes: 7 additions & 7 deletions packages/hello_world/sources/hello_world.move
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// 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;
module hello_world::hello_world;

/// Returns the "Hello World!" as a `String`.
public fun hello_world(): String {
b"Hello, World!".to_string()
}
// 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()
}
12 changes: 6 additions & 6 deletions packages/hello_world/tests/hello_world_tests.move
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[test_only]
module hello_world::hello_world_tests {
use hello_world::hello_world;
module hello_world::hello_world_tests;

#[test]
fun test_hello_world() {
assert!(hello_world::hello_world() == b"Hello, World!".to_string(), 0);
}
use hello_world::hello_world;

#[test]
fun test_hello_world() {
assert!(hello_world::hello_world() == b"Hello, World!".to_string(), 0);
}
6 changes: 1 addition & 5 deletions packages/samples/sources/move-basics/address.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#[allow(unused_variable)]
module book::address {
module book::address;

#[test] fun address_literal() {

Expand All @@ -24,7 +24,6 @@ use sui::address;
let addr_as_u256: u256 = address::to_u256(@0x1);
let addr = address::from_u256(addr_as_u256);
// ANCHOR_END: to_u256

}

#[test] fun address_string() {
Expand All @@ -35,7 +34,6 @@ use std::string::String;

let addr_as_string: String = address::to_string(@0x1);
// ANCHOR_END: to_string

}

#[test] fun address_bytes() {
Expand All @@ -46,6 +44,4 @@ use sui::address;
let addr_as_u8: vector<u8> = address::to_bytes(@0x1);
let addr = address::from_bytes(addr_as_u8);
// ANCHOR_END: to_bytes

}
}
3 changes: 1 addition & 2 deletions packages/samples/sources/move-basics/assert-and-abort.move
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module book::assert_abort {
module book::assert_abort;

#[test, expected_failure(abort_code = 1, location=Self)]
fun test_abort() {
Expand Down Expand Up @@ -50,4 +50,3 @@ public fun update_record(/* ... , */ user_has_access: bool, field_exists: bool)
/* ... */
}
// ANCHOR_END: error_const
}
20 changes: 20 additions & 0 deletions packages/samples/sources/move-basics/comments-block.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#[allow(unused_function)]
// ANCHOR: main
module book::comments_block;

fun /* you can comment everywhere */ go_wild() {
/* here
there
everywhere */ let a = 10;
let b = /* even here */ 10; /* and again */
a + b;
}
/* you can use it to remove certain expressions or definitions
fun empty_commented_out() {
}
*/
// ANCHOR_END: main
21 changes: 21 additions & 0 deletions packages/samples/sources/move-basics/comments-doc.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#[allow(unused_function, unused_const, unused_variable, unused_field)]
// ANCHOR: main
/// Module has documentation!
module book::comments_doc;

/// This is a 0x0 address constant!
const AN_ADDRESS: address = @0x0;

/// This is a struct!
public struct AStruct {
/// This is a field of a struct!
a_field: u8,
}

/// This function does something!
/// And it's documented!
fun do_something() {}
// ANCHOR_END: main
15 changes: 15 additions & 0 deletions packages/samples/sources/move-basics/comments-line.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#[allow(unused_function, unused_variable)]
// ANCHOR: main
module book::comments_line;

// let's add a note to everything!
fun some_function_with_numbers() {
let a = 10;
// let b = 10 this line is commented and won't be executed
let b = 5; // here comment is placed after code
a + b; // result is 15, not 10!
}
// ANCHOR_END: main
62 changes: 0 additions & 62 deletions packages/samples/sources/move-basics/comments.move

This file was deleted.

17 changes: 17 additions & 0 deletions packages/samples/sources/move-basics/constants-config.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// ANCHOR: config
module book::config;

const ITEM_PRICE: u64 = 100;
const TAX_RATE: u64 = 10;
const SHIPPING_COST: u64 = 5;

/// Returns the price of an item.
public fun item_price(): u64 { ITEM_PRICE }
/// Returns the tax rate.
public fun tax_rate(): u64 { TAX_RATE }
/// Returns the shipping cost.
public fun shipping_cost(): u64 { SHIPPING_COST }
// ANCHOR_END: config
13 changes: 13 additions & 0 deletions packages/samples/sources/move-basics/constants-naming.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#[allow(unused_const)]
module book::naming;

// ANCHOR: naming
/// Price of the item used at the shop.
const ITEM_PRICE: u64 = 100;

/// Error constant.
const EItemNotFound: u64 = 1;
// ANCHOR_END: naming
25 changes: 25 additions & 0 deletions packages/samples/sources/move-basics/constants-shop-price.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// ANCHOR: shop_price
module book::shop_price;

use sui::{coin::Coin, sui::SUI};

/// The price of an item in the shop.
const ITEM_PRICE: u64 = 100;
/// The owner of the shop, an address.
const SHOP_OWNER: address = @0xa11ce;

/// An item sold in the shop.
public struct Item {}

/// Purchase an item from the shop.
public fun purchase(coin: Coin<SUI>): Item {
assert!(coin.value() == ITEM_PRICE, 0);

transfer::public_transfer(coin, SHOP_OWNER);

Item {}
}
// ANCHOR_END: shop_price
67 changes: 8 additions & 59 deletions packages/samples/sources/move-basics/constants.move
Original file line number Diff line number Diff line change
@@ -1,67 +1,16 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module book::constants {
const MAX: u64 = 100;
module book::constants;

// however you can pass constant outside using a function
public fun max(): u64 {
MAX
}
const MAX: u64 = 100;

// or using
public fun is_max(num: u64): bool {
num == MAX
}
// however you can pass constant outside using a function
public fun max(): u64 {
MAX
}

// ANCHOR: shop_price
module book::shop_price {
use sui::coin::Coin;
use sui::sui::SUI;

/// The price of an item in the shop.
const ITEM_PRICE: u64 = 100;
/// The owner of the shop, an address.
const SHOP_OWNER: address = @0xa11ce;

/// An item sold in the shop.
public struct Item { /* ... */ }

/// Purchase an item from the shop.
public fun purchase(coin: Coin<SUI>): Item {
assert!(coin.value() == ITEM_PRICE, 0);

transfer::public_transfer(coin, SHOP_OWNER);

Item { /* ... */ }
}
}
// ANCHOR_END: shop_price
#[allow(unused_const)]
module book::naming {

// ANCHOR: naming
/// Price of the item used at the shop.
const ITEM_PRICE: u64 = 100;

/// Error constant.
const EItemNotFound: u64 = 1;
// ANCHOR_END: naming

}

// ANCHOR: config
module book::config {
const ITEM_PRICE: u64 = 100;
const TAX_RATE: u64 = 10;
const SHIPPING_COST: u64 = 5;

/// Returns the price of an item.
public fun item_price(): u64 { ITEM_PRICE }
/// Returns the tax rate.
public fun tax_rate(): u64 { TAX_RATE }
/// Returns the shipping cost.
public fun shipping_cost(): u64 { SHIPPING_COST }
// or using
public fun is_max(num: u64): bool {
num == MAX
}
// ANCHOR_END: config
Loading

0 comments on commit db007fd

Please sign in to comment.