diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c1e79273..55da4b3bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: branches: [master] env: - rust_version: 1.45.0 + rust_version: 1.53.0 jobs: lint: diff --git a/Cargo.lock b/Cargo.lock index 1153c6d35..d0527250f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler32" version = "1.0.4" @@ -695,11 +697,12 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lexical-core" -version = "0.6.2" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7043aa5c05dd34fb73b47acb8c3708eac428de4545ea3682ed2f11293ebd890" +checksum = "233853dfa6b87c7c00eb46a205802069263ab27e16b6bdd1b08ddf91a855e30c" dependencies = [ "arrayvec", + "bitflags", "cfg-if 0.1.10", "rustc_version", "ryu", diff --git a/changelog.md b/changelog.md index 71c30270a..c84e81f8b 100644 --- a/changelog.md +++ b/changelog.md @@ -12,7 +12,14 @@ See also the [rdkafka-sys changelog](rdkafka-sys/changelog.md). * Fix a segfault when calling `Consumer::position` on a consumer that was improperly configured ([#360]). +* Implement `std::iter::Extend<(String, String)>` and + `std::iter::FromIterator<(String, String)` for `ClientConfig` ([#367]). + + Thanks, [@djKooks]. + [#360]: https://github.com/fede1024/rust-rdkafka/issues/360 +[#367]: https://github.com/fede1024/rust-rdkafka/issues/367 +[@djKooks]: https://github.com/djKooks ## 0.26.0 (2021-03-16) diff --git a/rdkafka.suppressions b/rdkafka.suppressions index d2c4d9c00..c8d8f27bb 100644 --- a/rdkafka.suppressions +++ b/rdkafka.suppressions @@ -8,6 +8,7 @@ statx(file_name) fun:syscall fun:statx + fun:statx fun:_ZN3std3sys4unix2fs9try_statx* ... } @@ -17,6 +18,7 @@ statx(buf) fun:syscall fun:statx + fun:statx fun:_ZN3std3sys4unix2fs9try_statx* ... } diff --git a/src/config.rs b/src/config.rs index 2d173249c..2375f888b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,7 @@ use std::collections::HashMap; use std::ffi::{CStr, CString}; +use std::iter::FromIterator; use std::mem; use std::os::raw::c_char; use std::ptr; @@ -273,6 +274,26 @@ impl ClientConfig { } } +impl FromIterator<(String, String)> for ClientConfig { + fn from_iter(iter: I) -> ClientConfig + where + I: IntoIterator, + { + let mut config = ClientConfig::new(); + config.extend(iter); + config + } +} + +impl Extend<(String, String)> for ClientConfig { + fn extend(&mut self, iter: I) + where + I: IntoIterator, + { + self.conf_map.extend(iter) + } +} + /// Return the log level fn log_level_from_global_config() -> RDKafkaLogLevel { if log_enabled!(target: "librdkafka", Level::Debug) { @@ -298,3 +319,20 @@ pub trait FromClientConfigAndContext: Sized { /// Creates a client from a client configuration and a client context. fn from_config_and_context(_: &ClientConfig, _: C) -> KafkaResult; } + +#[cfg(test)] +mod tests { + use super::ClientConfig; + + #[test] + fn test_client_config_set_map() { + let mut config: ClientConfig = vec![("a".into(), "1".into()), ("b".into(), "1".into())] + .into_iter() + .collect(); + config.extend([("b".into(), "2".into()), ("c".into(), "3".into())]); + + assert_eq!(config.get("a").unwrap(), "1"); + assert_eq!(config.get("b").unwrap(), "2"); + assert_eq!(config.get("c").unwrap(), "3"); + } +} diff --git a/src/message.rs b/src/message.rs index 91dfad8d3..0f28f492b 100644 --- a/src/message.rs +++ b/src/message.rs @@ -27,8 +27,8 @@ pub enum Timestamp { impl Timestamp { /// Convert the timestamp to milliseconds since epoch. - pub fn to_millis(&self) -> Option { - match *self { + pub fn to_millis(self) -> Option { + match self { Timestamp::NotAvailable | Timestamp::CreateTime(-1) | Timestamp::LogAppendTime(-1) => { None }