-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sui/move] support dynamic access of child objects #4203
Comments
|
How long will it take to complete this feature |
If completed, can an object own infinitely many child objects, like Key-Value map? |
Yes! It can have an unbounded number |
This is a question for @tnowacki, but I think sometime in October |
Removing child objects by type would be useful for the following use case: // package1
struct Foo has key {
id: UID,
children: vector<ID>,
}
struct Bar<phantom FT> has key {
id: UID,
amount: Balance<FT>,
}
public fun pop_child_any_mint<FT>(parent: &mut Foo): Balance<FT> {
let Bar { id, amount } = remove_child_by_type<FT>(parent);
object::delete(id);
amount
}
// package2
// custom royalty collection in USDC and SUI
public fun custom_royalty_collection(foo: Foo) {
let ft = package1::pop_child_any_mint<USDC>(&mut foo);
let s = package1::pop_child_any_mint<SUI>(&mut foo);
// ...
} Ie. I know the type I want to get in a specific implementation, but want to create a generic interface for doing that for any type. Not sure how multiple children of the same type should be handled though. Return a vec of all, or first one at random, or ...? |
It would be ideal to also have native APIs to check whether a parent object owns a child object, and other helper methods as well. e.g. |
has_child_object is being included as a method: |
This is a step we have discussed that will significantly improve the expressiveness of Sui Move by allowing the implementation of collections that require pointer-like structures. The basic idea is:
remove_child_by_key<K: copy + drop, P: key, C: key>(parent: &mut P, key: &K): C
), a type (e.g.,remove_child_by_type<K, P: key, C: key(parent: &mut P): C
), by id (e.g.,remove_child_by_id<P: key, C: key>(parent: &mut P, id: ID): C
, or all of the above.The text was updated successfully, but these errors were encountered: