iter_merge/
storage.rs

1//! Storage backends
2
3pub(crate) mod array;
4pub use array::*;
5#[cfg(feature = "alloc")]
6pub(crate) mod vec;
7use core::fmt::Debug;
8
9#[cfg(feature = "alloc")]
10pub use vec::*;
11
12use crate::{
13    comparators::{ByOrd, tie_breaker},
14    internal::{PeekIter, StorageOps},
15    merge_iter::DefaultBuilder,
16};
17
18/// Marker trait for [`MergeIter`](crate::MergeIter) storage.
19pub trait Storage: StorageOps + Sized {
20    /// Create a new builder with default parameters for this storage
21    #[inline]
22    fn into_builder(self) -> DefaultBuilder<Self> {
23        DefaultBuilder::new(self, ByOrd, tie_breaker::InsertionOrder)
24    }
25}
26
27impl<S: StorageOps + Sized> Storage for S {}
28
29struct DebugFormatter<'a, S>(&'a S);
30
31impl<S> Debug for DebugFormatter<'_, S>
32where
33    S: Storage,
34    PeekIter<S::IT>: Debug,
35{
36    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
37        let mut d = f.debug_list();
38        self.0.map_items(|it| {
39            d.entry(it);
40        });
41        d.finish()
42    }
43}
44
45/// Utility that returns a [`Debug`] formatter of the items in [`Storage`]
46///
47/// Items are shown using standard [`debug_list`](core::fmt::Formatter::debug_list) format.
48/// See [this `Debug` impl](crate::storage::InternalArrayStorage::fmt) for an example.
49#[inline]
50pub fn debug_formatter<S>(storage: &'_ S) -> impl Debug + '_
51where
52    S: Storage,
53    PeekIter<S::IT>: Debug,
54{
55    DebugFormatter(storage)
56}