Crate map_to_const
source · [−]Expand description
Easily convert HashMap<K, V>
to constant [(K, V); N]
values.
Usage
use map_to_const::*;
use std::collections::HashMap;
fn main() {
// Create a HashMap in some manner. Ideally, this will be formatted
// and returned in an API response or similar.
let my_map = HashMap::from([("testing", "123"), ("hello", "world")]);
let const_value = map_to_const(&my_map, None);
println!("{const_value}");
// later in code, construct the hashmap from the `const` slice:
// let my_map = HashMap::from(MY_MAP);
}
Examples
You can check out sample usage of this crate in the examples/ folder in the project repo on GitHub.
Readme Docs
You can find the crate’s readme documentation on the
crates.io page, or alternatively in the README.md
file on the GitHub project repo.
Traits
Trait to retrieve the string value (i.e. name) of a type.
Functions
Converts a HashMap<K, V>
to a const
or constant [(K, V); N]
string representation, where N
is the number of key-value pairs in the
input map object.