diff options
author | Marcel Müller <m.mueller@ifm.com> | 2022-05-10 10:53:46 +0200 |
---|---|---|
committer | Marcel Müller <m.mueller@ifm.com> | 2022-05-12 08:51:12 +0200 |
commit | d0282cbd8197b6f33a74537be06d00b3cdc0f604 (patch) | |
tree | c1d8e0730d9501a5beba2363bd8af6a64bb648ae /crates | |
parent | 473801d5dd64ea9c2e669afe650ee210cd9edfa2 (diff) |
Add ConfigKind::Wrapped
Wrapping another config is very useful for narrowing down configs. This
patch adds this possibility for authors.
Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/core/tedge_api/src/config.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/core/tedge_api/src/config.rs b/crates/core/tedge_api/src/config.rs index 7357b497..bfb4cf88 100644 --- a/crates/core/tedge_api/src/config.rs +++ b/crates/core/tedge_api/src/config.rs @@ -70,6 +70,13 @@ pub enum ConfigKind { /// 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>), @@ -154,9 +161,7 @@ impl ConfigDescription { } match self.kind() { - ConfigKind::Array(conf) => { - doc = doc.append(Pretty::pretty(conf.as_terminal_doc(arena), arena)) - } + ConfigKind::Bool | ConfigKind::Integer | ConfigKind::Float | ConfigKind::String => (), ConfigKind::Struct(stc) => { doc = doc .append(arena.hardline()) @@ -175,10 +180,9 @@ impl ConfigDescription { Doc::hardline(), )) } - ConfigKind::HashMap(conf) => { + ConfigKind::Array(conf) | ConfigKind::HashMap(conf) | ConfigKind::Wrapped(conf) => { doc = doc.append(Pretty::pretty(conf.as_terminal_doc(arena), arena)) } - _ => (), }; doc.into_doc() |