emproof-com/nyxstone

rust: `assemble` generics forces caller to create two containers

Closed this issue · 1 comments

When implementing a small cli program using the rust bindings, I noticed that the generics in the assemble functions force the caller to create a HashMap<&str, u64>, which is only possible when also owning an additional container holding the Strings of the labels. When dynamically creating the labels, this forces the caller to have an additional container holding the actual Strings.

My proposal is changing the generics of the assemble functions to take AsRef<str> instead of &str. This way both Map<&str, _> and &Map<String, _> could be passed to the functions. The only downside to this change would be that rust will be unable to infer the type of an empty map, forcing the caller to specify the type of the map explicitly:

nyxstone.assemble(&assembly, 0, &HashMap::<&str, _>::new());

The downside of having to specify the type of the empty map could also be removed by having an additional function which has no labels argument, since the caller already knows that he will not need labels if he specified an empty map.