Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to declare global hashmap for slices? #170

Open
AchalaSB opened this issue Apr 3, 2020 · 0 comments
Open

How to declare global hashmap for slices? #170

AchalaSB opened this issue Apr 3, 2020 · 0 comments

Comments

@AchalaSB
Copy link

AchalaSB commented Apr 3, 2020

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)

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ad466c07c08b4177f9c675c5116bbc63

Above code is failed due to type errors

 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant