From 353d9fabcbe60dbd93dbba9665122e73feac5134 Mon Sep 17 00:00:00 2001 From: "alexander.rembridge" Date: Tue, 7 May 2024 21:56:05 +0100 Subject: [PATCH] Implement fmt::Display for Stream --- server/src/streaming/streams/stream.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/src/streaming/streams/stream.rs b/server/src/streaming/streams/stream.rs index 969ab681b..bbc747c68 100644 --- a/server/src/streaming/streams/stream.rs +++ b/server/src/streaming/streams/stream.rs @@ -4,6 +4,7 @@ use crate::streaming::topics::topic::Topic; use iggy::utils::byte_size::IggyByteSize; use iggy::utils::timestamp::IggyTimestamp; use std::collections::HashMap; +use std::fmt; use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; use std::sync::Arc; @@ -24,6 +25,15 @@ pub struct Stream { pub(crate) storage: Arc, } +impl fmt::Display for Stream { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "ID: {}, ", self.stream_id)?; + write!(f, "name: {}, ", self.name)?; + write!(f, "size bytes: {:?}, ", self.size_bytes)?; + write!(f, "messages count: {:?}", self.messages_count) + } +} + impl Stream { pub fn empty(id: u32, config: Arc, storage: Arc) -> Self { Stream::create(id, "", config, storage) @@ -81,5 +91,6 @@ mod tests { assert_eq!(stream.path, path); assert_eq!(stream.topics_path, topics_path); assert!(stream.topics.is_empty()); + assert_eq!("ID: 1, name: test, size bytes: 0, messages count: 0", format!("{}", stream)); } }