Thanks for the hint, but I can not assign the exists.version property to an existing variable.
version = exists.version;
leads to a syntax error:
syntax error [M0001], unexpected token ‘=’, expected one of token or sequence
public func storeAsset(id: Nat32, text: Text) : async ArtId {
let assetKey = next;
next += 1;
let version:Nat32 = 1;
let result = Trie.find(assets, key(id), Nat32.equal);
let exists = Option.isSome(result);
switch(result) {
case(?exists) {
version = exists.version;
D.print(debug_show(exists.version));
D.print(debug_show(version));
};
case(null) {
// entry not found in trie
};
};
let asset : Asset = {
id = id;
version = version;
text = text;
};
assets := Trie.replace(
assets,
key(assetKey),
Nat32.equal,
?asset,
).0;
return assetKey;
};