has_fields
Some macros helpful for processing forms with optional fields.
Usage
For instance, if you got a form like this:
let form = MyForm
Here are some macros that might help you:
-
has_fields::has_fields!
: Check if a struct has some fields. Returns a boolean.has_fields! // true
-
has_fields::require_fields
: Check if a struct has some fields. Returns aResult<(), Vec<&'static str>>
.require_fields! // Ok(()) require_fields! // Err(vec!["phone"])
Moreover, you can derive HasFields
trait for your struct, and use these methods:
-
num_fields
: Get the number ofSome(...)
or non-optional fields in a struct.form.num_fields // 2
License
The Unlicense
Contributing
If you have any ideas, feel free to open an issue or a PR.