mirror of https://github.com/fede1024/rust-rdkafka
Implement Extend and FromIterator for ClientConfig
This commit is contained in:
parent
29f5ccf731
commit
4ef41d8618
|
@ -7,7 +7,7 @@ on:
|
|||
branches: [master]
|
||||
|
||||
env:
|
||||
rust_version: 1.45.0
|
||||
rust_version: 1.53.0
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
|
|
|
@ -697,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",
|
||||
|
|
|
@ -15,8 +15,15 @@ See also the [rdkafka-sys changelog](rdkafka-sys/changelog.md).
|
|||
* Provide a mutable accessor (`Message::payload_mut`) for a message's
|
||||
payload ([#95]).
|
||||
|
||||
* Implement `std::iter::Extend<(String, String)>` and
|
||||
`std::iter::FromIterator<(String, String)` for `ClientConfig` ([#367]).
|
||||
|
||||
Thanks, [@djKooks].
|
||||
|
||||
[#95]: https://github.com/fede1024/rust-rdkafka/issues/95
|
||||
[#360]: https://github.com/fede1024/rust-rdkafka/issues/360
|
||||
[#367]: https://github.com/fede1024/rust-rdkafka/issues/367
|
||||
[@djKooks]: https://github.com/djKooks
|
||||
|
||||
<a name="0.26.0"></a>
|
||||
## 0.26.0 (2021-03-16)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<statx1>
|
||||
Memcheck:Param
|
||||
statx(file_name)
|
||||
fun:syscall
|
||||
fun:statx
|
||||
fun:statx
|
||||
fun:_ZN3std3sys4unix2fs9try_statx*
|
||||
...
|
||||
|
@ -15,7 +15,7 @@
|
|||
<statx2>
|
||||
Memcheck:Param
|
||||
statx(buf)
|
||||
fun:syscall
|
||||
fun:statx
|
||||
fun:statx
|
||||
fun:_ZN3std3sys4unix2fs9try_statx*
|
||||
...
|
||||
|
|
|
@ -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<I>(iter: I) -> ClientConfig
|
||||
where
|
||||
I: IntoIterator<Item = (String, String)>,
|
||||
{
|
||||
let mut config = ClientConfig::new();
|
||||
config.extend(iter);
|
||||
config
|
||||
}
|
||||
}
|
||||
|
||||
impl Extend<(String, String)> for ClientConfig {
|
||||
fn extend<I>(&mut self, iter: I)
|
||||
where
|
||||
I: IntoIterator<Item = (String, String)>,
|
||||
{
|
||||
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<C: ClientContext>: Sized {
|
|||
/// Creates a client from a client configuration and a client context.
|
||||
fn from_config_and_context(_: &ClientConfig, _: C) -> KafkaResult<Self>;
|
||||
}
|
||||
|
||||
#[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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ pub enum Timestamp {
|
|||
|
||||
impl Timestamp {
|
||||
/// Convert the timestamp to milliseconds since epoch.
|
||||
pub fn to_millis(&self) -> Option<i64> {
|
||||
match *self {
|
||||
pub fn to_millis(self) -> Option<i64> {
|
||||
match self {
|
||||
Timestamp::NotAvailable | Timestamp::CreateTime(-1) | Timestamp::LogAppendTime(-1) => {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue