Skip to content

Commit

Permalink
Implement fmt::Display for Partition
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-rembridge committed May 8, 2024
1 parent 2cd632a commit efb86c7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions server/src/streaming/partitions/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use dashmap::DashMap;
use iggy::consumer::ConsumerKind;
use iggy::utils::duration::IggyDuration;
use iggy::utils::timestamp::IggyTimestamp;
use std::fmt;
use std::sync::atomic::{AtomicU32, AtomicU64, Ordering};
use std::sync::Arc;

Expand Down Expand Up @@ -41,6 +42,16 @@ pub struct Partition {
pub(crate) storage: Arc<SystemStorage>,
}

impl fmt::Display for Partition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ID: {}, ", self.partition_id)?;
write!(f, "segments count: {}, ", self.get_segments_count())?;
write!(f, "current offset: {}, ", self.current_offset)?;
write!(f, "size bytes: {}, ", self.get_size_bytes())?;
write!(f, "messages count: {}", self.get_messages_count())
}
}

#[derive(Debug, PartialEq, Clone)]
pub struct ConsumerOffset {
pub kind: ConsumerKind,
Expand Down Expand Up @@ -211,6 +222,10 @@ mod tests {
Arc::new(AtomicU32::new(0)),
);

assert_eq!(
"ID: 3, segments count: 1, current offset: 0, size bytes: 0, messages count: 0",
format!("{}", partition)
);
assert_eq!(partition.stream_id, stream_id);
assert_eq!(partition.topic_id, topic_id);
assert_eq!(partition.partition_id, partition_id);
Expand Down

0 comments on commit efb86c7

Please sign in to comment.