Oh boy! It seems you've opened a few cans of worms all at once!
Going from top to bottom:
static mut
variables
These are highly discouraged in Rust -- the only instances they're used in is when writing some low-level constructs which are synchronized by OS apis. (In essence, not your day-to-day use case).
I assume you're trying to actually construct what'd otherwise be a global variable in another language. That's... not recommended in Rust, and although there are ways of doing that, it's often best to see how you can get around the global state. Keep H
locally in main
, and work off of that
, and come back to the topic of mutable globals when you're sure there are really big benefits which might come of them.
Turbofish syntax
When a type is generic and you wish to acess one of its members without elision (for example, you want to call a method on Vec<T>
without letting the compiler guess T
on its own), you need to use turbofish syntax.
This is written, in your case, as follows:
let x = HashMap::<String, A>::from(/* */);
Notice that the only real change is that there's a ::
before the open angle bracket. Another example would be Vec::<usize>::new
. This isn't always necessary though, since the compiler can often elide these things, but a good example of where it's commonly used is in .collect
on iterators:
my_data
.iter()
.map(|x| /* */)
.filter(|x| /* */)
.collect::<Vec<T>>();
Assigning to variables under a reference
If you have a variable:
let x: &mut usize = /* */;
And you wish to assign to the value which x
points at, then it is done as follows:
*x = 3;
This is distinguished from changing where x
points to which is done with:
let mut y = 4;
x = &mut y;
Note in this case, you'd have needed to declare x
itself mutable:
let mut x: &mut usize = /* */;
Strings galore
So, strings in Rust are always a bit of a pain point to beginners. We've unfortunately accrued a bit of technical debt in exchange for performance.
This is covered elsewhere and you can definitely find great resources if you look up "String
vs str
rust", but for now, know that "abc"
is an &str
, while you want String
so you'd do "abc".to_string()
.