diff --git a/crates/core/src/db/message_log.rs b/crates/core/src/db/message_log.rs index bd9c322ada..53d269a82c 100644 --- a/crates/core/src/db/message_log.rs +++ b/crates/core/src/db/message_log.rs @@ -155,14 +155,20 @@ impl Default for OpenOptions { } } -#[derive(Clone, Copy, Debug)] -struct Segment { - min_offset: u64, - size: u64, +/// A segment of a [`MessageLog`]. +/// +/// Represents a physical file holding a subset of the log. +#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] +pub struct Segment { + /// Message offset this segment starts with (zero-based). + pub min_offset: u64, + /// Size in bytes of this segment. + pub size: u64, } impl Segment { - fn name(&self) -> String { + /// Name of this segment, as it appears in its file name. + pub fn name(&self) -> String { format!("{:0>20}", self.min_offset) } } @@ -480,6 +486,12 @@ impl SegmentView { } } +impl From for Segment { + fn from(SegmentView { info, .. }: SegmentView) -> Self { + info + } +} + impl TryFrom for IterSegment { type Error = io::Error;