Fix indexes types

This commit is contained in:
Yuriy Dupyn 2024-02-04 18:13:05 +01:00
parent 89305b6126
commit 4c0f91ad33
3 changed files with 36 additions and 18 deletions

View file

@ -21,7 +21,7 @@ use crate::index::Index;
// ===Concrete Cursors===
pub struct ReadCursor<'a, T> {
header: StoreHeader,
indexes: Vec<Option<&'a Index<T, FilePosition>>>,
indexes: &'a [Option<Index<T, FilePosition>>],
file: File,
data_type: PhantomData<T>,
@ -30,7 +30,7 @@ pub struct ReadCursor<'a, T> {
pub struct WriteCursor<'a, T> {
header: &'a mut StoreHeader,
indexes: Vec<Option<&'a Index<T, FilePosition>>>,
indexes: &'a mut [Option<Index<T, FilePosition>>],
file: File,
data_type: PhantomData<T>,
@ -231,7 +231,7 @@ pub trait CursorWithStoreHeader<T>: PrimitiveCursor<T> {
#[async_trait]
pub trait CursorWithAccessToIndex<T>: CursorWithStoreHeader<T> {
fn indexes(&mut self) -> &[Option<&Index<T, FilePosition>>];
fn indexes(&mut self) -> &[Option<Index<T, FilePosition>>];
async fn find_in_index(&mut self, k: &T) -> Result<Option<FilePosition>>
where T: Encode + Decode + Ord + Send + Sync
@ -277,13 +277,13 @@ impl <T>CursorWithStoreHeader<T> for WriteCursor<'_, T> {
// ===CursorWithAccessToIndex===
impl <T>CursorWithAccessToIndex<T> for ReadCursor<'_, T> {
fn indexes(&mut self) -> &[Option<&Index<T, FilePosition>>] {
fn indexes(&mut self) -> &[Option<Index<T, FilePosition>>] {
&self.indexes
}
}
impl <T>CursorWithAccessToIndex<T> for WriteCursor<'_, T> {
fn indexes(&mut self) -> &[Option<&Index<T, FilePosition>>] {
fn indexes(&mut self) -> &[Option<Index<T, FilePosition>>] {
&self.indexes
}
}
@ -304,7 +304,7 @@ impl <'cursor, T> ReadCursor<'cursor, T> {
header: store.header.clone(),
file,
data_type: store.data_type,
indexes: todo!(),
indexes: &store.indexes,
eof_file_position: 0,
};
@ -337,7 +337,7 @@ impl <'cursor, T> WriteCursor<'cursor, T>
header: &mut store.header,
file,
data_type: store.data_type,
indexes: todo!(),
indexes: &mut store.indexes,
eof_file_position: 0,
};