style: builder style segment set (#5209)

This commit is contained in:
Matthias Seitz
2023-10-30 13:57:52 +01:00
committed by GitHub
parent e73ece945d
commit 07552ca149
2 changed files with 38 additions and 23 deletions

View File

@ -15,11 +15,19 @@ impl<DB: Database> SegmentSet<DB> {
}
/// Adds new [Segment] to collection.
pub fn add_segment<S: Segment<DB> + 'static>(mut self, segment: S) -> Self {
pub fn segment<S: Segment<DB> + 'static>(mut self, segment: S) -> Self {
self.inner.push(Arc::new(segment));
self
}
/// Adds new [Segment] to collection if it's [Some].
pub fn segment_opt<S: Segment<DB> + 'static>(self, segment: Option<S>) -> Self {
if let Some(segment) = segment {
return self.segment(segment)
}
self
}
/// Consumes [SegmentSet] and returns a [Vec].
pub fn into_vec(self) -> Vec<Arc<dyn Segment<DB>>> {
self.inner