diff --git a/Cargo.toml b/Cargo.toml index 4e7f4a2..24e0461 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kafka-settings" -version = "0.2.1" +version = "0.2.2" authors = ["Sebastian Rollen "] edition = "2018" diff --git a/src/settings.rs b/src/settings.rs index f0799f9..73299e4 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,4 +1,4 @@ -use serde::Deserialize; +use serde::{Deserialize, Deserializer}; #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "security_protocol")] @@ -13,9 +13,18 @@ pub enum SecurityProtocol { #[derive(Debug, Clone, Deserialize)] pub struct ConsumerSettings { pub group_id: String, + #[serde(deserialize_with = "vec_from_str")] pub input_topics: Vec, } +pub fn vec_from_str<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let s = String::deserialize(deserializer)?; + Ok(s.split(',').map(From::from).collect()) +} + #[derive(Debug, Clone, Deserialize)] pub struct KafkaSettings { pub bootstrap_servers: String,