Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions book/guides/code-quality-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ ctx.sender()

### Vector Has a Literal. And Associated Functions

`vector::empty` and `vector::singleton` are deprecated in MoveStdlib. Use vector literal syntax instead.

```move
// bad!
// bad! (vector::empty and vector::singleton are now deprecated)
let mut my_vec = vector::empty();
vector::push_back(&mut my_vec, 10);
let first_el = vector::borrow(&my_vec);
assert!(vector::length(&my_vec) == 1);
let singleton = vector::singleton(10); // also deprecated

// good!
let mut my_vec = vector[10];
Expand Down Expand Up @@ -593,4 +594,4 @@ Being friendly and helping reviewers understand the code!
// Note: can underflow if a value is smaller than 10.
// TODO: add an `assert!` here
let value = external_call(value, ctx);
```
```
8 changes: 5 additions & 3 deletions book/programmability/dynamic-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ and `Value` type parameters define the abilities that the key and value must hav
## Usage

The methods available for dynamic fields are straightforward: a field can be added with `add`,
removed with `remove`, and read with `borrow` and `borrow_mut`. Additionally, the `exists_` method
removed with `remove`, and read with `borrow` and `borrow_mut`. Additionally, the `exists` method
can be used to check if a field exists (for stricter checks with type, there is an
`exists_with_type` method).
`exists_with_type` method). Note: `exists_` is deprecated in favor of `exists`. To remove a field
if it exists and return an `Option`, use `remove_opt` (note: `remove_if_exists` is deprecated in
favor of `remove_opt`).

```move file=packages/samples/sources/programmability/dynamic-fields.move anchor=usage

Expand Down Expand Up @@ -184,4 +186,4 @@ on the ability to define them _later_ and change the type of the field.
## Next Steps

In the next section we will cover [Dynamic Object Fields](./dynamic-object-fields) and explain how
they differ from dynamic fields, and what are the implications of using them.
they differ from dynamic fields, and what are the implications of using them.
5 changes: 3 additions & 2 deletions book/programmability/dynamic-object-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ Let's list them for reference:

- `add` - adds a dynamic object field to the object
- `remove` - removes a dynamic object field from the object
- `remove_opt` - removes a dynamic object field if it exists, returning an `Option`
- `borrow` - borrows a dynamic object field from the object
- `borrow_mut` - borrows a mutable reference to a dynamic object field from the object
- `exists_` - checks if a dynamic object field exists
- `exists` - checks if a dynamic object field exists
- `exists_with_type` - checks if a dynamic object field exists with a specific type

Additionally, there is an `id` method which returns the `ID` of the `Value` object without
Expand Down Expand Up @@ -94,4 +95,4 @@ Both dynamic field and dynamic object fields are powerful features which allow f
solutions in applications. However, they are relatively low-level and require careful handling to
avoid orphaned fields. In the next section, we will introduce a higher-level abstraction -
[Dynamic Collections](./dynamic-collections) - which can help with managing dynamic fields and
objects more effectively.
objects more effectively.
Loading