Strongly-typed string keys for configuration.
A frequent task is to extract a typed value from an untyped Map<String, Object>
.
Typically, this is done via string keys: let port: u32 = map.get("port")?.parse()?
.
A slightly more type-safe approach is to associate certain types with corresponding
string constants:
```rust
extern crate typedkey; use typedkey::Key;
// PORT
is basically "port"
string with associated u32
type.
const PORT: Key
```
This crate provides basic building block for such strongly-typed strings. See [example] for a complete example of reading configuration, and the [blog post] for a more long winded explanation of the pattern.
Using string keys is totally fine for small isolated cases, but if this pattern
is pervasive, typed_key
can provide the following benefits: