Crates.io | glitchup_derive |
lib.rs | glitchup_derive |
version | 0.4.0 |
source | src |
created_at | 2019-07-27 18:16:21.295665 |
updated_at | 2019-10-08 15:39:46.950541 |
description | Helper macros for glitchup |
homepage | |
repository | https://github.com/Calmynt/glitchup |
max_upload_size | |
id | 152120 |
size | 13,682 |
glitchup_derive
A group of procedural macros to assist in the use of glitchup
. Check any updates on the changelog.
#[derive(MutConfig)]
This derivation macro is used to derive MutConfig
for any compatible struct. For a struct to be compatible, the following must apply:
Config
.isize
String
bool
Vec<{Supported Type (incl. Generic)}>
Option<{Supported Type (incl. Generic)}>
These specific primitives were selected due to the MutOptionVal
using said values.
The MutConfig
trait implements a to_hashmap
function, where the fields of the struct are converted into a HashMap<String, MutOptionVal>
to be used by a Mutation
.
#[derive(Debug, Deserialize, MutConfig)]
struct MainConfig {
mutation : MutationConfig,
mutations : Vec<Vec<String>> // works!
mapint : Vec<Vec<u8>> // fails!
}
#[derive(Debug, Deserialize, MutConfig)]
struct MutationConfig {
min : Option<isize>,
max : Option<isize>,
chunksize : isize,
}
In MainConfig
above, mapint
would fail, since it uses the incompatible type u8
. However, we need it in order for our application to work. Let's assume that no Mutation
will use it. Therefore, what we can do is add the #[ignore]
attribute:
#[derive(Debug, Deserialize, MutConfig)]
struct MainConfig {
mutation : MutationConfig,
mutations : Vec<Vec<String>> // works!
#[ignore]
mapint : Vec<Vec<u8>> // all ok now!
}
...
Any field tagged with #[ignore]
will not be included in to_hashmap(...)
.