You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
How we can declare global hashmap?
In my use case I want to insert some value to the key in init function and then using transfer function I want to transfer amount. At the time i have to modify the new state.
(PS: I'm want to compile this code into wasm and use that binary in Go, So using FFI in my code and make it as memory pointers)
Compiling playground v0.0.1 (/playground)
warning: unused `#[macro_use]` import
--> src/main.rs:1:1
|
1 | #[macro_use]
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0308]: mismatched types
--> src/main.rs:20:20
|
20 | HASHMAP.insert(sen, 100000);
| ^^^ expected `i32`, found slice `[i32]`
|
= note: expected reference `&'static i32`
found reference `&[i32]`
error[E0277]: the trait bound `&i32: std::borrow::Borrow<&[i32]>` is not satisfied
--> src/main.rs:35:40
|
35 | let sender_balance = match HASHMAP.get(&sen) {
| ^^^ the trait `std::borrow::Borrow<&[i32]>` is not implemented for `&i32`
error[E0308]: mismatched types
--> src/main.rs:45:24
|
45 | HASHMAP.insert(sen, sender_balance - amount);
| ^^^ expected `i32`, found slice `[i32]`
|
= note: expected reference `&'static i32`
found reference `&[i32]`
error[E0277]: the trait bound `&i32: std::borrow::Borrow<&[i32]>` is not satisfied
--> src/main.rs:46:47
|
46 | let recipient_balance = match HASHMAP.get(&recp) {
| ^^^ the trait `std::borrow::Borrow<&[i32]>` is not implemented for `&i32`
error[E0308]: mismatched types
--> src/main.rs:51:24
|
51 | HASHMAP.insert(recp, recipient_balance + amount);
| ^^^^ expected `i32`, found slice `[i32]`
|
= note: expected reference `&'static i32`
found reference `&[i32]`
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
please help me in reading/ inserting new value
TIA
The text was updated successfully, but these errors were encountered:
Hi,
How we can declare global hashmap?
In my use case I want to insert some value to the key in
init
function and then usingtransfer
function I want to transfer amount. At the time i have to modify the new state.(PS: I'm want to compile this code into wasm and use that binary in Go, So using FFI in my code and make it as memory pointers)
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ad466c07c08b4177f9c675c5116bbc63
Above code is failed due to type errors
please help me in reading/ inserting new value
TIA
The text was updated successfully, but these errors were encountered: