Skip to content

Commit

Permalink
Implement fmt::Display for Segment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-rembridge committed May 8, 2024
1 parent b271d8f commit 2cd632a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/src/streaming/segments/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::streaming::utils::file;
use futures::{pin_mut, TryStreamExt};
use iggy::error::IggyError;
use iggy::utils::timestamp::IggyTimestamp;
use std::sync::atomic::AtomicU64;
use std::sync::Arc;
use std::{fmt, sync::atomic::AtomicU64};
use tokio::io::AsyncWriteExt;
use tracing::{info, trace};

Expand Down Expand Up @@ -55,6 +55,14 @@ pub struct Segment {
pub(crate) storage: Arc<SystemStorage>,
}

impl fmt::Display for Segment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "stream ID: {}, ", self.stream_id)?;
write!(f, "topic ID: {}, ", self.topic_id)?;
write!(f, "partition ID: {}", self.partition_id)
}
}

impl Segment {
#[allow(clippy::too_many_arguments)]
pub fn create(
Expand Down Expand Up @@ -265,6 +273,10 @@ mod tests {
messages_count_of_parent_partition,
);

assert_eq!(
"stream ID: 1, topic ID: 2, partition ID: 3",
format!("{}", segment)
);
assert_eq!(segment.stream_id, stream_id);
assert_eq!(segment.topic_id, topic_id);
assert_eq!(segment.partition_id, partition_id);
Expand Down

0 comments on commit 2cd632a

Please sign in to comment.