structmap/lib.rs
1//! Implements the public traits that developers inherit from in order to properly utilize the
2//! derive macro's functionality in code conversion and generation.
3#![doc = include_str!("../README.md")]
4//!
5pub mod value;
6
7use std::collections::BTreeMap;
8
9use crate::value::Value;
10
11// Alias for BTreeMap with String keys and values
12pub type StringMap = BTreeMap<String, String>;
13
14// Alias for BTreeMap with String keys and generic values
15pub type GenericMap = BTreeMap<String, Value>;
16
17pub trait FromMap: Default {
18 /// Converts a `GenericMap` back into a structure.
19 /// __Constraints__: assumes that value types conform to the original types of the struct.
20 fn from_stringmap(hashmap: StringMap) -> Self;
21 fn from_genericmap(hashmap: GenericMap) -> Self;
22}
23
24pub trait ToMap: Default {
25 /// Generates a `StringMap` where value types are all casted to strings.
26 /// __Constraints__: one-way, will need additional work to re-convert to struct.
27 #[allow(clippy::wrong_self_convention)]
28 fn to_stringmap(structure: Self) -> StringMap;
29
30 /// Generates a `GenericMap` where value types are all encapsulated under a sum type.
31 /// __Constraints__: currently only supports primitive types for genericized values.
32 #[allow(clippy::wrong_self_convention)]
33 fn to_genericmap(structure: Self) -> GenericMap;
34}