Skip to content

Commit

Permalink
Merge pull request #3 from Overmuse/SR/default_serde
Browse files Browse the repository at this point in the history
Sr/default serde
  • Loading branch information
SebRollen authored Apr 3, 2021
2 parents cefbe8c + eaa9eeb commit e5056ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kafka-settings"
version = "0.2.1"
version = "0.2.2"
authors = ["Sebastian Rollen <[email protected]>"]
edition = "2018"

Expand Down
11 changes: 10 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::Deserialize;
use serde::{Deserialize, Deserializer};

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "security_protocol")]
Expand All @@ -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<String>,
}

pub fn vec_from_str<'de, D>(deserializer: D) -> Result<Vec<String>, 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,
Expand Down

0 comments on commit e5056ca

Please sign in to comment.