Closed WGB5445 closed 4 days ago
exist_object
only cares about the ID, and does not care about the Type.
We can make the exist_object
care the Type, but
If object_id exists but not the type T, should exist_object<T>(object_id)
return false?
exist_object
only cares about the ID, and does not care about the Type.We can make the
exist_object
care the Type, butIf object_id exists but not the type T, should
exist_object<T>(object_id)
return false?
Would it be better to provide two functions that can be combined by user?
Would it be better to provide two functions that can be combined by user?
How to name it? It is too complex for the user. We need to decide by the scenario.
In the Table case, the user only cares about if the key exists and does not care about the value Type. Because the user will check if the key exists and then add the key-value pair. If the raw_table::contains(key)
care about the value type, will cause an error.
In the Object case, the ObjectID is generated via the system. The user can not construct the ObjectID, so the exist_object<T>(object_id)
can care about the value type. But the raw_table
implemention needs to refactor.
How about private a native function raw_table::borrow_option<T>(key):&Option<T>
? and implement the contains
function in Move.
In raw_table native implementation, why we only use key layout to representing a Table, instead of both key and value layout?
The current table defination:
/// A structure representing a single table.
pub struct Table {
handle: ObjectID,
key_layout: MoveTypeLayout,
content: BTreeMap<Vec<u8>, TableRuntimeValue>,
size_increment: i64,
}
How about define table like this:
/// A structure representing a single table.
pub struct Table {
handle: ObjectID,
key_layout: MoveTypeLayout,
value_layout: MoveTypeLayout,
content: BTreeMap<Vec<u8>, TableRuntimeValue>,
size_increment: i64,
}
The key_layout
is for serializing the Key
to vec<u8>
, and putting it in content: BTreeMap<Vec<u8>, TableRuntimeValue>
. The value_layout in TableRuntimeValue
.
use exists_object_with_type<T: key>(object_id: ObjectID): bool
When we get an Object ID, there seems to be no way to get the relationship between the ID and the Object type.
Currently it can only be determined through borrow:
We may need a function to determine whether the ID is of a certain type: