Commit Graph

137 Commits

Author SHA1 Message Date
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
ccce46eba4 formatting fixup
make fmt
(cargo fmt --all)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:14:23 +02:00
Wolfgang Bumiller
863a16a5bc whitespace cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:13:37 +02:00
Wolfgang Bumiller
4c9a8b5c88 cleanup use statements
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:12:49 +02:00
Wolfgang Bumiller
f074a9e60b cleanup Cargo.toml files
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:09:54 +02:00
Wolfgang Bumiller
1f11c4adf9 sys: rustfmt workaround
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 12:46:21 +02:00
Wolfgang Bumiller
63b17d4eb5 tools: Cargo.toml: cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 12:36:35 +02:00
Wolfgang Bumiller
97f41473db rename tools::raw to tools::fd
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 12:36:24 +02:00
Dietmar Maurer
3497f97a7d proxmox-tools/src/lib.rs: fix doc test 2019-08-05 10:12:08 +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
Dietmar Maurer
d6d65be42e add nodename helper (copied from proxmox-backup) 2019-08-03 17:00:02 +02:00
Dietmar Maurer
ce18d8c035 src/linux/procfs.rs: moved from proxmox-backup 2019-08-03 16:19:11 +02:00
Dietmar Maurer
51d891af5d new helper create_dir_chown
moved from proxmox-backup.
2019-08-03 12:21:20 +02:00
Dietmar Maurer
9f63a6506e src/fs.rs: new module for fs related helpers 2019-08-03 11:49:14 +02:00
Dietmar Maurer
909520d191 add src/linux/magic.rs - moved from proxmox-backup 2019-08-03 09:19:32 +02:00
Wolfgang Bumiller
e985dc8f84 api-test: import struct tests
This is a bigger set of tests for the type-side (mostly for
`struct`s) of the #[api] macro, tasting serialization and
verifiers in various forms.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-01 14:40:13 +02:00
Wolfgang Bumiller
75e90ebb25 api: support HashSet<String> as api type
This is just an array of strings in json, or a
semicolon-separated string on the command line.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-01 11:20:11 +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
26e4b205ac tools: add remaining common regexps
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 11:45:45 +02:00
Wolfgang Bumiller
1bc52e2482 tools: add common_regex with IP_REGEX for now
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 11:45:22 +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
7cbc6d0962 api: add a meta module to help with macro impls
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:08:55 +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
Wolfgang Bumiller
f340968773 macro: ability to rename enum variants via an attribute
In PVE we have multiple different enum types: hyphenated,
all-caps, underscores.

By default our api-macro enums will convert CamelCase to
underscores, so we need a way to represent the rest:

enum AnEnum {
	CaseOne, // becomes "case_one",
	#[api(rename = "case-two")]
	CaseTwo, // "case-two",
	#[api(rename = "CASE_THREE")]
	CaseThree,
}

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:52:25 +02:00