diff --git a/book/guides/code-quality-checklist.md b/book/guides/code-quality-checklist.md index 75656d51..1a750311 100644 --- a/book/guides/code-quality-checklist.md +++ b/book/guides/code-quality-checklist.md @@ -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]; @@ -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); -``` +``` \ No newline at end of file diff --git a/book/programmability/dynamic-fields.md b/book/programmability/dynamic-fields.md index 27bb303a..54dbc019 100644 --- a/book/programmability/dynamic-fields.md +++ b/book/programmability/dynamic-fields.md @@ -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 @@ -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. \ No newline at end of file diff --git a/book/programmability/dynamic-object-fields.md b/book/programmability/dynamic-object-fields.md index 4d640cfb..b5c62182 100644 --- a/book/programmability/dynamic-object-fields.md +++ b/book/programmability/dynamic-object-fields.md @@ -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 @@ -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. \ No newline at end of file