summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge_lib
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-07-01 21:47:26 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-07-03 09:25:34 +0200
commit79a6a1ca5f2b95e17e88f7a8b5342740e1644254 (patch)
treea41be8141f8e9500f0849f4187cc00e84c88ea46 /crates/core/tedge_lib
parent690d3fe859878c6d2dd474b8cbabd0a245bd3264 (diff)
Add config helper type: SocketAddr
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/core/tedge_lib')
-rw-r--r--crates/core/tedge_lib/src/config/mod.rs3
-rw-r--r--crates/core/tedge_lib/src/config/socket_addr.rs40
2 files changed, 43 insertions, 0 deletions
diff --git a/crates/core/tedge_lib/src/config/mod.rs b/crates/core/tedge_lib/src/config/mod.rs
index 2b8e82c1..7b0a5fa1 100644
--- a/crates/core/tedge_lib/src/config/mod.rs
+++ b/crates/core/tedge_lib/src/config/mod.rs
@@ -9,3 +9,6 @@ pub use one_or_many::OneOrMany;
mod port;
pub use port::Port;
+
+mod socket_addr;
+pub use socket_addr::SocketAddr;
diff --git a/crates/core/tedge_lib/src/config/socket_addr.rs b/crates/core/tedge_lib/src/config/socket_addr.rs
new file mode 100644
index 00000000..db2c46ce
--- /dev/null
+++ b/crates/core/tedge_lib/src/config/socket_addr.rs
@@ -0,0 +1,40 @@
+/// A helper type for specifying an IP address in the configuartion
+///
+/// This type wraps a [std::net::SocketAddr](std::net::SocketAddr) for specifying an IP address in
+/// the configuration. It implements [tedge_api::AsConfig](tedge_api::AsConfig) for convenient use.
+#[derive(
+ Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq, serde::Deserialize, serde::Serialize,
+)]
+pub struct SocketAddr(std::net::SocketAddr);
+
+impl Into<std::net::SocketAddr> for SocketAddr {
+ fn into(self) -> std::net::SocketAddr {
+ self.0
+ }
+}
+
+impl tedge_api::AsConfig for SocketAddr {
+ fn as_config() -> tedge_api::ConfigDescription {
+ tedge_api::ConfigDescription::new(
+ "A socket address".to_string(),
+ tedge_api::ConfigKind::String,
+ Some(indoc::indoc! {r#"
+ A String that represents a socket address
+
+ ## Examples
+
+ A socket address can either be an IPv4 address:
+
+ ```toml
+ "127.0.0.1"
+ ```
+
+ Or an IPv6 address:
+
+ ```toml
+ "::1"
+ ```
+ "#}),
+ )
+ }
+}