From 2abbb637e30ffbb6387d23231b32a45de39cd63b Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 11 Dec 2023 20:50:08 +0900 Subject: [PATCH] index: add wrapper functions to DefaultReadonlyIndex to remove pub(super) field --- lib/src/default_index/mutable.rs | 2 +- lib/src/default_index/readonly.rs | 10 +++++++++- lib/src/default_index/store.rs | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/default_index/mutable.rs b/lib/src/default_index/mutable.rs index 218a487315..bbb1ad96f0 100644 --- a/lib/src/default_index/mutable.rs +++ b/lib/src/default_index/mutable.rs @@ -487,6 +487,6 @@ impl MutableIndex for DefaultMutableIndex { .as_any() .downcast_ref::() .expect("index to merge in must be a DefaultReadonlyIndex"); - self.0.merge_in(other.0.clone()); + self.0.merge_in(other.as_segment().clone()); } } diff --git a/lib/src/default_index/readonly.rs b/lib/src/default_index/readonly.rs index 1b04bb457c..342c8f821d 100644 --- a/lib/src/default_index/readonly.rs +++ b/lib/src/default_index/readonly.rs @@ -380,9 +380,17 @@ impl IndexSegment for ReadonlyIndexSegment { /// Commit index backend which stores data on local disk. #[derive(Debug)] -pub struct DefaultReadonlyIndex(pub(super) Arc); +pub struct DefaultReadonlyIndex(Arc); impl DefaultReadonlyIndex { + pub(super) fn from_segment(segment: Arc) -> Self { + DefaultReadonlyIndex(segment) + } + + pub(super) fn as_segment(&self) -> &Arc { + &self.0 + } + pub fn as_composite(&self) -> CompositeIndex { self.0.as_composite() } diff --git a/lib/src/default_index/store.rs b/lib/src/default_index/store.rs index f1f137ae8f..9c3142298d 100644 --- a/lib/src/default_index/store.rs +++ b/lib/src/default_index/store.rs @@ -236,7 +236,7 @@ impl IndexStore for DefaultIndexStore { } else { self.index_at_operation(store, op).unwrap() }; - Box::new(DefaultReadonlyIndex(index_segment)) + Box::new(DefaultReadonlyIndex::from_segment(index_segment)) } fn write_index( @@ -257,6 +257,6 @@ impl IndexStore for DefaultIndexStore { "Failed to associate commit index file with a operation {op_id:?}: {err}" )) })?; - Ok(Box::new(DefaultReadonlyIndex(index_segment))) + Ok(Box::new(DefaultReadonlyIndex::from_segment(index_segment))) } }