I'm trying to re-create a Solidity contract in Vyper for a demonstration and am trying to figure out the best way to replicate adding/removing from an array of structs... As far as I can tell I'd have to use a hashmap of [uint256, mystruct] and then keep track of the index with a separate variable... is that the correct way to do this? What about for removing or zeroing a struct from the hashmap?
Solidity Code:
struct MyStruct {
string name;
uint age;
}
MyStruct[] public myStructs;
uint256 structCount;
// add
myStructs.push("Alice", 22);
structCount += 1;
// remove
delete myStructs[0];
structCount -= 1;
Work-in-progress Vyper Code:
struct MyStruct:
name: String[64]
age: uint256
myStructs: public(HashMap[uint256, MyStruct])
structIndex: uint256
structCount: uint256
# add
self.myStructs[self.structIndex] = MyStruct({name: "Alice", age: 22})
self.structIndex += 1
self.structCount += 1
# remove
thisStruct: MyStruct = self.myStructs[0]
# is this the only way to do this?
thisStruct.name = ""
thisStruct.age = 0
self.structCount -= 1