Skip to content

Commit

Permalink
doc: documents segmented_log::MetaWithIdx
Browse files Browse the repository at this point in the history
  • Loading branch information
arindas committed Feb 26, 2024
1 parent b1de935 commit b70ba84
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/storage/commit_log/segmented_log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,24 @@ use std::{
time::Duration,
};

/// Represent metadata for records in the [`SegmentedLog`].
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct MetaWithIdx<M, Idx> {
/// Generic metadata for the record as necessary
pub metadata: M,

/// Index of the record within the [`SegmentedLog`].
pub index: Option<Idx>,
}

impl<M, Idx> MetaWithIdx<M, Idx>
where
Idx: Eq,
{
/// Returns a [`Some`]`(`[`MetaWithIdx`]`)` containing this instance's `metadata` and the
/// provided `anchor_idx` if this indices match or this instance's `index` is `None`.
///
/// Returns `None` if this instance contains an `index` and the indices mismatch.
pub fn anchored_with_index(self, anchor_idx: Idx) -> Option<Self> {
let index = match self.index {
Some(idx) if idx != anchor_idx => None,
Expand All @@ -150,6 +158,8 @@ where
}
}

/// Record type alias for [`SegmentedLog`] using [`MetaWithIdx`] for the generic metadata
/// parameter.
pub type Record<M, Idx, T> = super::Record<MetaWithIdx<M, Idx>, T>;

#[derive(Debug)]
Expand Down

0 comments on commit b70ba84

Please sign in to comment.