Skip to content

Commit c4c1d8c

Browse files
authored
Derives serde::Serialize on Statistics (#616)
I realize that there is a `stats_raw` trait method, but it would be better to not have to re-type out the statistics fields myself. This came about because I would like to act on many of the individual fields locally via some aggregations, but then output them back out (along with other fields in a larger status struct) as a JSON-encoded string, e.g.: ```rs #[derive(Serialize)] pub struct Status { pub sample_field: u64, pub sample_field_2: boolean, pub statistics: Statistics, } ```
1 parent b3f3201 commit c4c1d8c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/statistics.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
1313
use std::collections::HashMap;
1414

15-
use serde::Deserialize;
15+
use serde::{Deserialize, Serialize};
1616

1717
/// Overall statistics.
18-
#[derive(Deserialize, Debug, Default, Clone)]
18+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
1919
pub struct Statistics {
2020
/// The name of the librdkafka handle.
2121
pub name: String,
@@ -73,7 +73,7 @@ pub struct Statistics {
7373
}
7474

7575
/// Per-broker statistics.
76-
#[derive(Deserialize, Debug, Default, Clone)]
76+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
7777
pub struct Broker {
7878
/// The broker hostname, port, and ID, in the form `HOSTNAME:PORT/ID`.
7979
pub name: String,
@@ -168,7 +168,7 @@ pub struct Broker {
168168
///
169169
/// These values are not exact; they are sampled estimates maintained by an
170170
/// HDR histogram in librdkafka.
171-
#[derive(Deserialize, Debug, Default, Clone)]
171+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
172172
pub struct Window {
173173
/// The smallest value.
174174
pub min: i64,
@@ -202,7 +202,7 @@ pub struct Window {
202202
}
203203

204204
/// A topic and partition specifier.
205-
#[derive(Deserialize, Debug, Default, Clone)]
205+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
206206
pub struct TopicPartition {
207207
/// The name of the topic.
208208
pub topic: String,
@@ -211,7 +211,7 @@ pub struct TopicPartition {
211211
}
212212

213213
/// Per-topic statistics.
214-
#[derive(Deserialize, Debug, Default, Clone)]
214+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
215215
pub struct Topic {
216216
/// The name of the topic.
217217
pub topic: String,
@@ -226,7 +226,7 @@ pub struct Topic {
226226
}
227227

228228
/// Per-partition statistics.
229-
#[derive(Deserialize, Debug, Default, Clone)]
229+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
230230
pub struct Partition {
231231
/// The partition ID.
232232
pub partition: i32,
@@ -299,7 +299,7 @@ pub struct Partition {
299299
}
300300

301301
/// Consumer group manager statistics.
302-
#[derive(Deserialize, Debug, Default, Clone)]
302+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
303303
pub struct ConsumerGroup {
304304
/// The local consumer group handler's state.
305305
pub state: String,
@@ -321,7 +321,7 @@ pub struct ConsumerGroup {
321321
}
322322

323323
/// Exactly-once semantics statistics.
324-
#[derive(Deserialize, Debug, Default, Clone)]
324+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
325325
pub struct ExactlyOnceSemantics {
326326
/// The current idempotent producer state.
327327
pub idemp_state: String,

0 commit comments

Comments
 (0)