Wolfgang Bumiller
7f2ae4f272
[clippy] api-test: remove unnecessary lifetimes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-22 09:15:03 +02:00
Wolfgang Bumiller
025eaf5519
api-macro: fix non-async test case after adding verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-16 12:21:32 +02:00
Wolfgang Bumiller
bb937395f7
macro: functions: call verify() on all parameters
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-16 10:18:33 +02:00
Wolfgang Bumiller
a7b9c8d89e
fixup tests for router change
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@errno.eu>
2019-08-15 20:26:18 +02:00
Wolfgang Bumiller
bb2639bf40
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 14:34:23 +02:00
Wolfgang Bumiller
8e24ada75a
macro: support deriving Display for newtypes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 14:01:21 +02:00
Wolfgang Bumiller
50f5115718
macro: fix enum verify method
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 14:00:59 +02:00
Wolfgang Bumiller
37cf2e6208
macro: fixup previous commit: remove hardcoded error
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 13:30:35 +02:00
Wolfgang Bumiller
0046e5e33a
macro: experimental support for enums with values
...
enum Foo {
Variant1(Type), // allowed
Variant2(Type, Type), // not allowed
Variant3 { name: Type }, // not allowed
}
In the simple case of a single type we simply drop the
automatically derived `FromStr`/`Display` impls and expect
the user to implement them manually, while in the `verify()`
method we simply match on self and forward to the inner
verifier.
So to get "tagged unions" in the API, implement a proper
API type for each variant, then add an enum with 1-tuple
variants.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 12:00:12 +02:00
Wolfgang Bumiller
fb5670c5b5
macro: remove exact futures-preview version
...
Otherwise we have .16 and .17 in the same project. And we
can't go to .18 currently until hyper/tokio git-master are
in sync again.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 10:42:19 +02:00
Wolfgang Bumiller
169bf79c72
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
ed503f689d
macro: split enum handler into separate module
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
59d0c72642
macro: split struct handlers into separate submodules
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
841c2a218d
macro: split function handler into separate file
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
080f62916e
macro: errors shouldn't discard the code
...
Otherwise we'll get even more errors.
Consider this example:
#[api(...)]
struct Foo { ... }
impl MyTrait for Foo { ... }
If the #[api] macro fails and does not at least produce the
`struct Foo{}` along with its `compile_error!()` output,
then in addition to our macro errors, we'll see errors about
trying to implement `MyTrait` for an unknown thing called
`Foo`.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 14:04:28 +02:00
Wolfgang Bumiller
cad8f2f1c3
macro: implement #[derive(FromStr)] for newtypes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 13:54:17 +02:00
Wolfgang Bumiller
e3273d6172
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 13:13:35 +02:00
Wolfgang Bumiller
cfa6f0f67f
cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 13:13:19 +02:00
Wolfgang Bumiller
bb3e2859e4
macro: derive ser/de for newtypes just like structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:29:12 +02:00
Wolfgang Bumiller
a53e8c5e82
macro: make sure errors are separated
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:17:37 +02:00
Wolfgang Bumiller
818dc25478
macro: factor out newtype handler
...
Reuse verifier code of structs fields. Add handling of
'validate' methods for fields.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:14:47 +02:00
Wolfgang Bumiller
dfdf354b0d
macro: more quote -> quote_spanned changes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:09:58 +02:00
Wolfgang Bumiller
af04fc5764
macro: remove unused add_verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:09:29 +02:00
Wolfgang Bumiller
d78142302c
formatting fixup
...
add #[rustfmt::skip] to our macros...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 09:45:14 +02:00
Wolfgang Bumiller
ef13b38632
macro: improve error output
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 15:42:07 +02:00
Wolfgang Bumiller
3a36ff78df
macro: clear a warning
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 14:39:18 +02:00
Wolfgang Bumiller
14acfcd5cd
macro: recurse into struct field verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 14:35:00 +02:00
Wolfgang Bumiller
3c31381fb2
macro: support 'pattern' verifier in structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 14:32:35 +02:00
Wolfgang Bumiller
2a4af329a7
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 15:20:55 +02:00
Wolfgang Bumiller
d5ee03da9f
macro: support serialize_with and deserialize_with
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 15:19:51 +02:00
Wolfgang Bumiller
a6fcaf27e5
macro: don't enforce the AsOptionStr type on formats
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 10:33:07 +02:00
Wolfgang Bumiller
fab0210287
api, macro: implement 'format' verifier for structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 10:06:32 +02:00
Wolfgang Bumiller
b77733c8ef
api: macro: implement minimum/maximum_length checks
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:40:04 +02:00
Wolfgang Bumiller
f1f4c14819
api: verify: rename Verify to TestMinMax
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:30:32 +02:00
Wolfgang Bumiller
20b8c709c6
api: add helper module for verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:16:05 +02:00
Wolfgang Bumiller
30105c5743
refactor struct handling
...
less spaghetti code accumulation, more purpose oriented
functions
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 12:01:20 +02:00
Wolfgang Bumiller
bb62206e27
macro: disable derive_default for now
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 15:24:39 +02:00
Wolfgang Bumiller
5d9fe0d24d
macro: fixup: don't create unwanted default impl snippets
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 15:20:45 +02:00
Wolfgang Bumiller
8523e03486
macro: partial support for automatic Default derivation
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 15:17:25 +02:00
Wolfgang Bumiller
50eadf23fb
macro: support Option in deserialization
...
When deserializing we currently expect all fields to be
available, but we actually want Option types to be truly
optional...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:50:23 +02:00
Wolfgang Bumiller
ce5fa31721
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:30:48 +02:00
Wolfgang Bumiller
061cc5b525
implement accessors for types with defaults
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:09:15 +02:00
Wolfgang Bumiller
cb2c260f87
default to not serializing None options
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 13:22:18 +02:00
Wolfgang Bumiller
d9f57ed107
cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 11:08:38 +02:00
Wolfgang Bumiller
ec1ad87193
macro: replace named struct handler
...
We now derive Serialize and Deserialize automatically.
This way we'll be able to add verifiers right into the
structs, support our 'rename' functionality, and our
'default' handling etc. which needs to be compatible with
what we have in perl.
Ideally this will also give us the option to mark structs as
being perl-compatible "property strings"
(PVE::JSONSchema::parse_property_string()) and automatically
derive FromStr for structs on demand.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 11:04:55 +02:00
Wolfgang Bumiller
0a8a9cdb5b
macro: error handling
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 10:04:38 +02:00
Wolfgang Bumiller
bb62dde9b0
macro: common defs: add default, and sort
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 10:01:59 +02:00
Wolfgang Bumiller
bb673ec0db
macro: improved error output
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 09:58:07 +02:00
Wolfgang Bumiller
183125b1cd
macro: named struct: allow short form for fields
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 15:05:26 +02:00
Wolfgang Bumiller
c54afe1be4
macro: add spans to more errors
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:59:09 +02:00