matthewpratt13 / feo-new

A novel blockchain programming language written in Rust (WIP)
GNU General Public License v3.0
1 stars 0 forks source link

Add `Mapping` indexing functionality #95

Open matthewpratt13 opened 1 week ago

matthewpratt13 commented 1 week ago

Either (a) add a get(&k) function to the stdlib (like Rust); or (b) use a special syntax to access values at a given key in a Mapping<K, V> (perhaps dot syntax; i.e., treat Mapping similar to structs?).

E.g.,

let mut balances: Mapping<h160, u256> = Mapping::new();
let alice_addr: h160 = $0x12345123451234512345; 
balances.insert(alice, 0x1_000_000 as u256);

let alice_balance = balances.get(&alice_addr);
// or
let alice_balance = balances.alice_addr;
matthewpratt13 commented 1 week ago

An obvious problem with the latter is that one may be forced to use identifiers as keys and not other types.

I.e.,

let alice_balance = balances.$0x12345123451234512345;

may not be possible