diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-12 10:26:10 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-12 10:26:10 +0200 |
commit | affc50251b13ee661e4ac13293b3c926ca06163a (patch) | |
tree | 97f53d74aef8b9174f4274b45087206da2d9529a | |
parent | 9e5162fcfd2dfd0ed090f18c698e91b6b0e29908 (diff) | |
parent | ac5ee07dcf94edf3ae79486ffac73d8c3a54841c (diff) |
Merge branch 'feature/add_tedge_api/integrate-api' into feature/add_tedge_api_impl
Integrates the latest API changes for self-describing configuration
types.
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r-- | Cargo.lock | 354 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | crates/core/tedge_api/Cargo.toml | 8 | ||||
-rw-r--r-- | crates/core/tedge_api/examples/print_config.rs | 149 | ||||
-rw-r--r-- | crates/core/tedge_api/src/config.rs | 379 | ||||
-rw-r--r-- | crates/core/tedge_api/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/core/tedge_api/src/message.rs | 7 | ||||
-rw-r--r-- | crates/core/tedge_api/src/plugin.rs | 13 | ||||
-rw-r--r-- | crates/core/tedge_api/tedge_config_derive/Cargo.toml | 15 | ||||
-rw-r--r-- | crates/core/tedge_api/tedge_config_derive/src/lib.rs | 382 | ||||
-rw-r--r-- | crates/core/tedge_api/tests/derive_config.rs | 76 |
11 files changed, 1297 insertions, 94 deletions
@@ -72,9 +72,9 @@ checksum = "48ad219abc0c06ca788aface2e3a1970587e3413ab70acd20e54b6ec524c1f8f" dependencies = [ "argh_shared", "heck 0.3.3", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -84,6 +84,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38de00daab4eac7d753e97697066238d67ce9d7e2d823ab4f72fe14af29f3f33" [[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] name = "assert-json-diff" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -162,9 +168,9 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -173,9 +179,9 @@ version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -489,9 +495,9 @@ checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" dependencies = [ "heck 0.4.0", "proc-macro-error", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -582,6 +588,15 @@ dependencies = [ ] [[package]] +name = "coolor" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaebeb52e38d53b890ebcb723ff23462f39353d4e73db48284591e6395a1c25e" +dependencies = [ + "crossterm", +] + +[[package]] name = "core-foundation-sys" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -644,6 +659,20 @@ dependencies = [ ] [[package]] +name = "crossbeam" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] name = "crossbeam-channel" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -678,6 +707,16 @@ dependencies = [ ] [[package]] +name = "crossbeam-queue" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] name = "crossbeam-utils" version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -688,6 +727,31 @@ dependencies = [ ] [[package]] +name = "crossterm" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85525306c4291d1b73ce93c8acf9c339f9b213aef6c1d85c3830cbf1c16325c" +dependencies = [ + "bitflags", + "crossterm_winapi", + "libc", + "mio 0.7.14", + "parking_lot 0.11.2", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" +dependencies = [ + "winapi", +] + +[[package]] name = "csv" version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -715,8 +779,8 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" dependencies = [ - "quote 1.0.10", - "syn 1.0.82", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -737,10 +801,10 @@ checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.32", - "quote 1.0.10", + "proc-macro2 1.0.38", + "quote 1.0.18", "strsim 0.10.0", - "syn 1.0.82", + "syn 1.0.93", ] [[package]] @@ -750,8 +814,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core", - "quote 1.0.10", - "syn 1.0.82", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -768,7 +832,7 @@ checksum = "c73af209b6a5dc8ca7cbaba720732304792cddc933cfea3d74509c2b1ef2f436" dependencies = [ "num-bigint 0.4.3", "num-traits", - "syn 1.0.82", + "syn 1.0.93", ] [[package]] @@ -1057,9 +1121,9 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -1578,9 +1642,9 @@ version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45a95a48d0bc28f9af628286e8a4da09f96f34a97744a2e9a5a4db9814ad527d" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -1600,6 +1664,15 @@ dependencies = [ ] [[package]] +name = "minimad" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd37b2e65fbd459544194d8f52ed84027e031684335a062c708774c09d172b0b" +dependencies = [ + "once_cell", +] + +[[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1617,6 +1690,19 @@ dependencies = [ [[package]] name = "mio" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "mio" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ba42135c6a5917b9db9cd7b293e5409e1c6b041e6f9825e92e55a894c63b6f8" @@ -1660,9 +1746,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7e25b214433f669161f414959594216d8e6ba83b6679d3db96899c0b4639033" dependencies = [ "cfg-if 1.0.0", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -1794,6 +1880,16 @@ dependencies = [ ] [[package]] +name = "nu-ansi-term" +version = "0.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7bca0d33a384280d1563b97f49cb95303df9fa22588739a04b7d8015c1ccd50" +dependencies = [ + "overload", + "winapi", +] + +[[package]] name = "num" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1959,6 +2055,12 @@ dependencies = [ ] [[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] name = "owo-colors" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2080,9 +2182,9 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -2370,10 +2472,23 @@ dependencies = [ ] [[package]] +name = "pretty" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83f3aa1e3ca87d3b124db7461265ac176b40c277f37e503eaa29c9c75c037846" +dependencies = [ + "arrayvec", + "log", + "termcolor", + "typed-arena", + "unicode-segmentation", +] + +[[package]] name = "pretty_assertions" -version = "1.0.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0cfe1b2403f172ba0f234e500906ee0a3e493fb81092dac23ebefe129301cc" +checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" dependencies = [ "ansi_term", "ctor", @@ -2398,9 +2513,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", "version_check", ] @@ -2410,8 +2525,8 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", + "proc-macro2 1.0.38", + "quote 1.0.18", "version_check", ] @@ -2426,9 +2541,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.32" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +checksum = "9027b48e9d4c9175fa2218adf3557f91c1137021739951d4932f5f8268ac48aa" dependencies = [ "unicode-xid 0.2.2", ] @@ -2491,9 +2606,9 @@ checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" dependencies = [ "anyhow", "itertools", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -2529,11 +2644,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.10" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" dependencies = [ - "proc-macro2 1.0.32", + "proc-macro2 1.0.38", ] [[package]] @@ -2992,9 +3107,9 @@ version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3038,9 +3153,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" dependencies = [ "darling", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3060,9 +3175,9 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3088,6 +3203,27 @@ dependencies = [ ] [[package]] +name = "signal-hook" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio 0.7.14", + "signal-hook", +] + +[[package]] name = "signal-hook-registry" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3173,9 +3309,9 @@ checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck 0.3.3", "proc-macro-error", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3219,12 +3355,12 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.82" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "04066589568b72ec65f42d65a1a52436e954b168773148893c020269563decf2" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", + "proc-macro2 1.0.38", + "quote 1.0.18", "unicode-xid 0.2.2", ] @@ -3356,8 +3492,14 @@ dependencies = [ "downcast-rs", "futures", "miette", + "nu-ansi-term", + "pretty", + "pretty_assertions", "serde", "static_assertions", + "tedge_config_derive", + "termcolor", + "termimad", "thiserror", "tokio", "tokio-util 0.7.0", @@ -3396,6 +3538,16 @@ dependencies = [ ] [[package]] +name = "tedge_config_derive" +version = "0.1.0" +dependencies = [ + "proc-macro-error", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", +] + +[[package]] name = "tedge_core" version = "0.1.0" dependencies = [ @@ -3516,14 +3668,28 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] +name = "termimad" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c14caf224b3f3d43d93d0532098f9e4906bd79e0978a2e10951f17aab7898b" +dependencies = [ + "coolor", + "crossbeam", + "crossterm", + "minimad", + "thiserror", + "unicode-width", +] + +[[package]] name = "terminal_size" version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3546,9 +3712,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7cad0a06f9a61e94355aa3b3dc92d85ab9c83406722b1ca5e918d4297c12c23" dependencies = [ "cfg-if 1.0.0", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", "version_check", ] @@ -3558,9 +3724,9 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4235dbf7ea878b3ef12dea20a59c134b405a66aafc4fc2c7b9935916e289e735" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3619,9 +3785,9 @@ version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3695,7 +3861,7 @@ dependencies = [ "bytes", "libc", "memchr", - "mio", + "mio 0.8.1", "num_cpus", "once_cell", "parking_lot 0.12.0", @@ -3723,9 +3889,9 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3861,10 +4027,10 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9403f1bafde247186684b230dc6f38b5cd514584e8bec1dd32514be4745fa757" dependencies = [ - "proc-macro2 1.0.32", + "proc-macro2 1.0.38", "prost-build", - "quote 1.0.10", - "syn 1.0.82", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -3918,9 +4084,9 @@ version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", ] [[package]] @@ -4038,6 +4204,12 @@ dependencies = [ ] [[package]] +name = "typed-arena" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" + +[[package]] name = "typenum" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -4253,9 +4425,9 @@ dependencies = [ "bumpalo", "lazy_static", "log", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", "wasm-bindgen-shared", ] @@ -4277,7 +4449,7 @@ version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" dependencies = [ - "quote 1.0.10", + "quote 1.0.18", "wasm-bindgen-macro-support", ] @@ -4287,9 +4459,9 @@ version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" dependencies = [ - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.82", + "proc-macro2 1.0.38", + "quote 1.0.18", + "syn 1.0.93", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3,6 +3,7 @@ members = [ "crates/common/*", "crates/core/*", + "crates/core/tedge_api/tedge_config_derive", "crates/tests/*", "plugins/plugin_avg", "plugins/plugin_httpstop", diff --git a/crates/core/tedge_api/Cargo.toml b/crates/core/tedge_api/Cargo.toml index afcd9800..619e769e 100644 --- a/crates/core/tedge_api/Cargo.toml +++ b/crates/core/tedge_api/Cargo.toml @@ -14,8 +14,14 @@ thiserror = "1.0.30" tokio = { version = "1.16.1", features = ["sync", "time"] } tokio-util = "0.7.0" toml = "0.5.8" +serde = { version = "1.0.136", features = ["derive"] } +pretty = { version = "0.11.3", features = ["termcolor"] } +termcolor = "1.1.3" +termimad = "0.20.1" +nu-ansi-term = "0.45.1" +tedge_config_derive = { version = "0.1.0", path = "tedge_config_derive" } [dev-dependencies] -serde = { version = "1.0.136", features = ["derive"] } +pretty_assertions = "1.2.1" static_assertions = "1.1.0" tokio = { version = "1.16.1", features = ["full"] } diff --git a/crates/core/tedge_api/examples/print_config.rs b/crates/core/tedge_api/examples/print_config.rs new file mode 100644 index 00000000..ba6e7a6b --- /dev/null +++ b/crates/core/tedge_api/examples/print_config.rs @@ -0,0 +1,149 @@ +use std::collections::HashMap; + +use nu_ansi_term::Color; +use pretty::Arena; +use tedge_api::{ + config::{AsConfig, ConfigDescription, ConfigKind}, + Config, +}; +struct Port(u64); + +impl AsConfig for Port { + fn as_config() -> ConfigDescription { + ConfigDescription::new( + String::from("Integer"), + ConfigKind::Integer, + Some("A TCP port number is an integer between 0 and 65535"), + ) + } +} + +struct VHost; + +impl AsConfig for VHost { + fn as_config() -> ConfigDescription { + ConfigDescription::new( + String::from("VHost"), + ConfigKind::Struct(vec![("name", None, String::as_config())]), + Some("A virtual host definition"), + ) + } +} + +fn main() { + let arena = Arena::new(); + + let doc = Vec::<String>::as_config(); + let rendered_doc = doc.as_terminal_doc(&arena); + + let mut output = String::new(); + + rendered_doc.render_fmt(80, &mut output).unwrap(); + + println!( + "------- Output for {}", + std::any::type_name::<Vec<String>>() + ); + println!("{}", output); + + let arena = Arena::new(); + + let doc = ConfigDescription::new( + String::from("ServerConfig"), + ConfigKind::Struct(vec![ + ("port", None, Port::as_config()), + ("interface", None, String::as_config()), + ("virtual_hosts", None, Vec::<VHost>::as_config()), + ("headers", None, HashMap::<String, String>::as_config()), + ]), + Some("Specify how the server should be started\n\n## Note\n\nThis is a reallly really loooooooooooooooooong loooooooooooooooooooong new *line*."), + ); + let rendered_doc = doc.as_terminal_doc(&arena); + + let mut output = String::new(); + + rendered_doc.render_fmt(80, &mut output).unwrap(); + + println!( + "Configuration for {} plugin kinds", + Color::White.bold().paint(doc.name()) + ); + println!( + "{}", + Color::White.dimmed().bold().paint(format!( + "=================={}=============", + std::iter::repeat('=') + .take(doc.name().len()) + .collect::<String>() + )) + ); + println!("------- Output for ServerConfig"); + println!("{}", output); + let arena = Arena::new(); + + #[derive(Config)] + #[config(tag = "type")] + /// An Nginx virtual host + /// + /// # Note + /// + /// This is an example and as such is nonsense + enum NginxVHost { + /// A simple host consisting of a string + Simple(String), + /// A more complex host that can also specify its port + Complex { + /// the name of the VHost + name: String, + port: Port, + }, + UndocumentedComplex { + num: u16, + foo: f32, + }, + } + + #[derive(Config)] + #[config(untagged)] + enum DebugLevel { + /// Enables debug output + /// + /// And info of course + Debug, + /// Only pertinent information will be logged + Info, + /// A custom debug level + Custom(String), + } + + #[derive(Config)] + struct NginxConfig { + vhosts: Vec<NginxVHost>, + debug_level: DebugLevel, + allow_priv_ports: bool, + } + + let doc = NginxConfig::as_config(); + let rendered_doc = doc.as_terminal_doc(&arena); + + let mut output = String::new(); + + rendered_doc.render_fmt(80, &mut output).unwrap(); + + println!("------- Output for NginxConfig"); + println!( + "Configuration for {} plugin kinds", + Color::White.bold().paint(doc.name()) + ); + println!( + "{}", + Color::White.dimmed().bold().paint(format!( + "=================={}=============", + std::iter::repeat('=') + .take(doc.name().len()) + .collect::<String>() + )) + ); + println!("{}", output); + println!("-------"); +} diff --git a/crates/core/tedge_api/src/config.rs b/crates/core/tedge_api/src/config.rs new file mode 100644 index 00000000..90bee595 --- /dev/null +++ b/crates/core/tedge_api/src/config.rs @@ -0,0 +1,379 @@ +use std::collections::HashMap; + +use nu_ansi_term::Color; +use pretty::{Arena, Doc, DocAllocator, Pretty, RefDoc}; +use serde::Serialize; +use termimad::MadSkin; + +/// Generic config that represents what kind of config a plugin wishes to accept +#[derive(Debug, Serialize, PartialEq)] +pub struct ConfigDescription { + name: String, + kind: ConfigKind, + doc: Option<&'static str>, +} + +impl ConfigDescription { + /// Construct a new generic config explanation + #[must_use] + pub fn new(name: String, kind: ConfigKind, doc: Option<&'static str>) -> Self { + Self { name, kind, doc } + } + + /// Get a reference to the config's documentation. + #[must_use] + pub fn doc(&self) -> Option<&'static str> { + self.doc + } + + /// Get a reference to the config's kind. + #[must_use] + pub fn kind(&self) -> &ConfigKind { + &self.kind + } + + /// Set or replace the documentation of this [`Config`] + #[must_use] + pub fn with_doc(mut self, doc: Option<&'static str>) -> Self { + self.doc = doc; + self + } + + /// Get the config's name. + #[must_use] + pub fn name(&self) -> &str { + &self.name + } +} + +/// How an enum is represented +#[derive(Debug, Serialize, PartialEq)] +pub enum EnumVariantRepresentation { + /// The enum is represented by a string + /// + /// This is the case with unit variants for example + String(&'static str), + /// The enum is represented by the value presented here + Wrapped(Box<ConfigDescription>), +} + +/// The kind of enum tagging used by the [`ConfigKind`] +#[derive(Debug, Serialize, PartialEq)] +pub enum ConfigEnumKind { + /// An internal tag with the given tag name + Tagged(&'static str), + /// An untagged enum variant + Untagged, +} + +/// The specific kind a [`Config`] represents +#[derive(Debug, Serialize, PartialEq)] +pub enum ConfigKind { + /// Config represents a boolean `true`/`false` + Bool, + + /// Config represents an integer `1, 10, 200, 10_000, ...` + /// + /// # Note + /// + /// The maximum value that can be represented is between [`i64::MIN`] and [`i64::MAX`] + Integer, + + /// Config represents a floating point value `1.0, 20.235, 3.1419` + /// + /// # Note + /// Integers are also accepted and converted to their floating point variant + /// + /// The maximum value that can be represented is between [`f64::MIN`] and [`f64::MAX`] + Float, + + /// Config represents a string + String, + + /// Wrap another config + /// + /// This is particularly useful if you want to restrict another kind. The common example is a + /// `Port` config object which is represented as a `u16` but with an explanation of what it is + /// meant to represent. + Wrapped(Box<ConfigDescription>), + + /// Config represents an array of values of the given [`ConfigKind`] + Array(Box<ConfigDescription>), + + /// Config represents a hashmap of named configurations of the same type + /// + /// # Note + /// + /// The key is always a [`String`] so this only holds the value config + HashMap(Box<ConfigDescription>), + + /// Config represents a map of dif |