Module sui::dynamic_object_field
Similar to sui::dynamic_field, this module allows for the access of dynamic fields. But unlike, sui::dynamic_field the values bound to these dynamic fields must be objects themselves. This allows for the objects to still exist within in storage, which may be important for external tools. The difference is otherwise not observable from within Move.
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::address;
use sui::dynamic_field;
use sui::hex;
use sui::object;
use sui::tx_context;
Struct Wrapper
public struct Wrapper<Name> has copy, drop, store
Fields
- name: Name
Function add
Adds a dynamic object field to the object object: &mut UID at field specified by name: Name.
Aborts with EFieldAlreadyExists if the object already has that field with that name.
public fun add<Name: copy, drop, store, Value: key, store>(object: &mut sui::object::UID, name: Name, value: Value)
Function borrow
Immutably borrows the objects dynamic object field with the name specified by name: Name.
Aborts with EFieldDoesNotExist if the object does not have a field with that name.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public fun borrow<Name: copy, drop, store, Value: key, store>(object: &sui::object::UID, name: Name): &Value
Function borrow_mut
Mutably borrows the objects dynamic object field with the name specified by name: Name.
Aborts with EFieldDoesNotExist if the object does not have a field with that name.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public fun borrow_mut<Name: copy, drop, store, Value: key, store>(object: &mut sui::object::UID, name: Name): &mut Value
Function remove
Removes the objects dynamic object field with the name specified by name: Name and returns
the bound object.
Aborts with EFieldDoesNotExist if the object does not have a field with that name.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public fun remove<Name: copy, drop, store, Value: key, store>(object: &mut sui::object::UID, name: Name): Value
Function exists
Returns true if and only if the object has a dynamic object field with the name specified by name: Name.
public fun exists<Name: copy, drop, store>(object: &sui::object::UID, name: Name): bool
Function exists_with_type
Returns true if and only if the object has a dynamic field with the name specified by name: Name with an assigned value of type Value.
public fun exists_with_type<Name: copy, drop, store, Value: key, store>(object: &sui::object::UID, name: Name): bool
Function id
Returns the ID of the object associated with the dynamic object field.
Returns none otherwise
public fun id<Name: copy, drop, store>(object: &sui::object::UID, name: Name): std::option::Option<sui::object::ID>
Function remove_opt
Removes the dynamic object field if it exists. Returns some(Value) if it exists or none
otherwise.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public fun remove_opt<Name: copy, drop, store, Value: key, store>(object: &mut sui::object::UID, name: Name): std::option::Option<Value>
Function replace
Removes the existing value at name (if any) and adds value in its place.
Returns the old value if it existed, or none otherwise.
Note: the old and new value types may differ.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified ValueOld type.
public fun replace<Name: copy, drop, store, ValueNew: key, store, ValueOld: key, store>(object: &mut sui::object::UID, name: Name, value: ValueNew): std::option::Option<ValueOld>
Macro function borrow_or_add
Immutably borrows the field value, adding it with $default if it doesn't exist.
Note that $default is evaluated only if the field does not already exist.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public macro fun borrow_or_add<$Name: copy, drop, store, $Value: key, store>($object: &mut sui::object::UID, $name: $Name, $default: $Value): &$Value
Macro function borrow_mut_or_add
Mutably borrows the field value, adding it with $default if it doesn't exist.
Note that $default is evaluated only if the field does not already exist.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public macro fun borrow_mut_or_add<$Name: copy, drop, store, $Value: key, store>($object: &mut sui::object::UID, $name: $Name, $default: $Value): &mut $Value
Macro function get_do
If the field exists, calls $f on an immutable reference to the value; otherwise, does nothing.
This is like getting an Option<&Value> then calling std::option::do.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public macro fun get_do<$Name: copy, drop, store, $Value: key, store, $R: drop>($object: &sui::object::UID, $name: $Name, $f: |&$Value| -> $R)
Macro function get_mut_do
If the field exists, calls $f on a mutable reference to the value; otherwise, does nothing.
This is like getting an Option<&mut Value> then calling std::option::do.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public macro fun get_mut_do<$Name: copy, drop, store, $Value: key, store, $R: drop>($object: &mut sui::object::UID, $name: $Name, $f: |&mut $Value| -> $R)
Macro function get_fold
If the field exists, applies $some to an immutable reference to the value; otherwise, returns $none.
This is like getting an Option<&Value> then calling std::option::fold.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public macro fun get_fold<$Name: copy, drop, store, $Value: key, store, $R>($object: &sui::object::UID, $name: $Name, $none: $R, $some: |&$Value| -> $R): $R
Macro function get_mut_fold
If the field exists, applies $some to a mutable reference to the value; otherwise, returns $none.
This is like getting an Option<&mut Value> then calling std::option::fold.
Aborts with EFieldTypeMismatch if the field exists, but the value object does not have the
specified type.
public macro fun get_mut_fold<$Name: copy, drop, store, $Value: key, store, $R>($object: &mut sui::object::UID, $name: $Name, $none: $R, $some: |&mut $Value| -> $R): $R
Function exists_
public fun exists_<Name: copy, drop, store>(object: &sui::object::UID, name: Name): bool
Function internal_add
public(package) fun internal_add<Name: copy, drop, store, Value: key>(object: &mut sui::object::UID, name: Name, value: Value)
Function internal_borrow
public(package) fun internal_borrow<Name: copy, drop, store, Value: key>(object: &sui::object::UID, name: Name): &Value
Function internal_borrow_mut
public(package) fun internal_borrow_mut<Name: copy, drop, store, Value: key>(object: &mut sui::object::UID, name: Name): &mut Value
Function internal_remove
public(package) fun internal_remove<Name: copy, drop, store, Value: key>(object: &mut sui::object::UID, name: Name): Value
Function internal_exists_with_type
public(package) fun internal_exists_with_type<Name: copy, drop, store, Value: key>(object: &sui::object::UID, name: Name): bool
Macro function add_impl
macro fun add_impl<$Name: copy, drop, store, $Value: key>($object: &mut sui::object::UID, $name: $Name, $value: $Value)
Macro function borrow_impl
macro fun borrow_impl<$Name: copy, drop, store, $Value: key>($object: &sui::object::UID, $name: $Name): &$Value
Macro function borrow_mut_impl
macro fun borrow_mut_impl<$Name: copy, drop, store, $Value: key>($object: &mut sui::object::UID, $name: $Name): &mut $Value
Macro function remove_impl
macro fun remove_impl<$Name: copy, drop, store, $Value: key>($object: &mut sui::object::UID, $name: $Name): $Value
Macro function exists_with_type_impl
macro fun exists_with_type_impl<$Name: copy, drop, store, $Value: key>($object: &sui::object::UID, $name: $Name): bool