How to return handle for a global dictionary object

I am an absolute newbie in Rust.

I have a successfully working spellchecker using web-assembly that I use from my web page. This spellchecker was built using C++ and Emscripten. It was based on the similar project that uses Hunspell but I am using the entire vocabulary as data inside the wasm. It works in a very simple way.

  1. the create method call (made only once at the start) will setup the vocabulary in the form of a hash-map and returns a 'handle' back to the calling JavaScript code
  2. later when the user enters a word, JavaScript calls 'suggest' method with the same handle and the word as arguments that will search the hash-map (and do some string manipulations) and finds suggestions and returns them.

Now the question about Rust. (I have created and run some example libs that interact between JavaScript and wasm using wasm-bindgen. ... but cannot proceed more)

I want to achieve the above using Rust. However I am not able to find a way to

  1. create the object and return the handle at the start
  2. should I create a lib or binary...

Please point me into right direction so that I can make a start.
Please let me know what more details I need to provide.

Thanks

Are you aware of the Rust and WebAssembly book? It provides a good introduction to compiling Rust to WASM and might be helpful to you if you haven't already known about it:

https://rustwasm.github.io/docs/book/introduction.html

Thanks for your prompt response.
Yes. Like I said above I have used that information and am able to bring up a wasm lib that can interact with JavaScript (to and from) in my webpage .... but that cannot create an 'object' that will remain in the memory forever and will 'serve' any requests made against it later.
Hope I have made myself clear

I have NO experience with WebAssembly but can you try with a static variable initialised by a LazyLock?

use std::collections::HashMap;

static HANDLE: std::sync::LazyLock<HashMap<&str, &str>> = std::sync::LazyLock::new(|| {
    HashMap::from([
        ("key1", "value1"),
        ("key2", "value2"),
    ])
});

fn main() {
    println!("{}",*HANDLE.get_key_value(&"key1").unwrap().1);
}

Okay. If I understand this, you are populating the hash-map in the main function. How can I do this in a library ..........Library does not have a main function. Correct me if wrong.

Can web-assembly be used for Rust binaries like it can be used for Rust libraries?, If yes, how?

That's the beauty of LazyLock, it will populate the first time it is accessed.
So you can put your static LazyLock in your lib.
The first time you access it, it will populate.