Skip to content

Commit

Permalink
better links
Browse files Browse the repository at this point in the history
  • Loading branch information
damirka committed Aug 27, 2024
1 parent 418bcf1 commit 190e397
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
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
23 changes: 23 additions & 0 deletions book/src/move-basics/standard-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ and which module implements it.

</div>

## Integer Modules

The Move Standard Library provides a set of functions associated with integer types. These functions
are split into multiple modules, each associated with a specific integer type. The modules should
not be imported directly, but their functions are available on every integer value.

> All of the modules provide the same set of functions. Namely, `max`, `diff`,
> `divide_and_round_up`, `sqrt` and `pow`.
<!-- Custom CSS addition in the theme/custom.css -->
<div class="modules-table">

| Module | Description |
| ---------------------------------------------------------------------- | ----------------------------- |
| [std::u8](https://docs.sui.io/references/framework/move-stdlib/u8) | Functions for the `u8` type |
| [std::16](https://docs.sui.io/references/framework/move-stdlib/u64) | Functions for the `u16` type |
| [std::u32](https://docs.sui.io/references/framework/move-stdlib/u64) | Functions for the `u32` type |
| [std::u64](https://docs.sui.io/references/framework/move-stdlib/u64) | Functions for the `u64` type |
| [std::u128](https://docs.sui.io/references/framework/move-stdlib/u128) | Functions for the `u128` type |
| [std::u256](https://docs.sui.io/references/framework/move-stdlib/u256) | Functions for the `u256` type |

</div>

## Exported Addresses

Standard Library exports one named address - `std = 0x1`.
Expand Down
13 changes: 7 additions & 6 deletions book/src/programmability/hot-potato-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ will cover in the next section.

The pattern is used in various forms in the Sui Framework. Here are some examples:

- `sui::borrow` - uses hot potato to ensure that the borrowed value is returned to the correct
container.
- `sui::transfer_policy` - defines a `TransferRequest` - a hot potato which can only be consumed if
all conditions are met.
- `sui::token` - in the Closed Loop Token system, an `ActionRequest` carries the information about
the performed action and collects approvals similarly to `TransferRequest`.
- [sui::borrow](https://docs.sui.io/references/framework/sui-framework/borrow) - uses hot potato to
ensure that the borrowed value is returned to the correct container.
- [sui::transfer_policy](https://docs.sui.io/references/framework/sui-framework/transfer_policy) -
defines a `TransferRequest` - a hot potato which can only be consumed if all conditions are met.
- [sui::token](https://docs.sui.io/references/framework/sui-framework/token) - in the Closed Loop
Token system, an `ActionRequest` carries the information about the performed action and collects
approvals similarly to `TransferRequest`.

## Summary

Expand Down
20 changes: 12 additions & 8 deletions book/src/programmability/sui-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ still part of the same framework._

<div class="modules-table">

| Module | Description | Chapter |
| ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------- |
| [sui::bcs](https://docs.sui.io/references/framework/sui-framework/bcs) | Implements the BCS encoding and decoding functions | [Binary Canonical Serialization](./bcs.md) |
| Module | Description | Chapter |
| ---------------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------ |
| [sui::bcs](https://docs.sui.io/references/framework/sui-framework/bcs) | Implements the BCS encoding and decoding functions | [Binary Canonical Serialization](./bcs.md) |
| [sui::borrow](https://docs.sui.io/references/framework/sui-framework/borrow) | Implements the borrowing mechanic for borrowing by _value_ | [Hot Potato](./hot-potato-pattern.md) |
| [sui::hex](https://docs.sui.io/references/framework/sui-framework/hex) | Implements the hex encoding and decoding functions | - |
| [sui::types](https://docs.sui.io/references/framework/sui-framework/types) | Provides a way to check if the type is a One-Time-Witness | [One Time Witness](./one-time-witness.md) |

## Exported Addresses

Expand Down Expand Up @@ -100,11 +103,12 @@ Commerce:
- sui::transfer_policy
- sui::bcs
- sui::hex
- sui::math
- sui::types
- sui::borrow
Utilities:
+ sui::bcs
+ sui::hex
- sui::math (deprecated)
+ sui::types
+ sui::borrow
- sui::authenticator
Expand Down
27 changes: 12 additions & 15 deletions packages/samples/sources/move-basics/vector.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#[allow(unused_variable)]
module book::vector_syntax {
#[test] fun test_vector() {

// ANCHOR: literal
// An empty vector of bool elements.
let empty: vector<bool> = vector[];
Expand All @@ -21,7 +20,6 @@ let vv: vector<vector<u8>> = vector[
}

#[test] fun vector_methods() {

// ANCHOR: methods
let mut v = vector[10u8, 20, 30];

Expand All @@ -34,24 +32,23 @@ let last_value = v.pop_back();
assert!(last_value == 40, 2);
// ANCHOR_END: methods
}

}


module book::non_droppable_vec {

// ANCHOR: no_drop
/// A struct without `drop` ability.
public struct NoDrop {}

#[test]
fun test_destroy_empty() {
// Initialize a vector of `NoDrop` elements.
let v = vector<NoDrop>[];

// While we know that `v` is empty, we still need to call
// the explicit `destroy_empty` function to discard the vector.
v.destroy_empty();
}
/// A struct without `drop` ability.
public struct NoDrop {}

#[test]
fun test_destroy_empty() {
// Initialize a vector of `NoDrop` elements.
let v = vector<NoDrop>[];

// While we know that `v` is empty, we still need to call
// the explicit `destroy_empty` function to discard the vector.
v.destroy_empty();
}
// ANCHOR_END: no_drop
}

0 comments on commit 190e397

Please sign in to comment.