Skip to main content

vecdb/traits/
any_readable.rs

1use crate::{AnyVec, ReadableVec, TypedVec, i64_to_usize};
2
3/// Type-erased trait for collectable vectors.
4pub trait AnyReadableVec: AnyVec {
5    /// Returns the number of items in the specified range.
6    fn range_count(&self, from: Option<i64>, to: Option<i64>) -> usize {
7        let len = self.len();
8        let from = from.map(|i| i64_to_usize(i, len)).unwrap_or_default();
9        let to = to.map(|i| i64_to_usize(i, len)).unwrap_or(len);
10        to.saturating_sub(from)
11    }
12
13    /// Returns the total size in bytes of items in the specified range.
14    fn range_weight(&self, from: Option<i64>, to: Option<i64>) -> usize {
15        self.range_count(from, to) * self.value_type_to_size_of()
16    }
17}
18
19impl<V> AnyReadableVec for V
20where
21    V: TypedVec,
22    V: ReadableVec<V::I, V::T>,
23{
24}