Use new cursors

This commit is contained in:
Yuriy Dupyn 2024-02-03 19:17:47 +01:00
parent a37c3a5e77
commit 2261fe39de
3 changed files with 81 additions and 283 deletions

View file

@ -59,7 +59,7 @@ trait PrimitiveCursor<T> {
}
#[async_trait]
trait CursorWithStoreHeader<T>: PrimitiveCursor<T> {
pub trait CursorWithStoreHeader<T>: PrimitiveCursor<T> {
fn header(&self) -> &StoreHeader;
async fn read_entry_header(&mut self) -> Result<EntryHeaderWithDataSize> {
@ -103,6 +103,7 @@ trait CursorWithStoreHeader<T>: PrimitiveCursor<T> {
Ok(Some(entry))
}
// ===Debugging===
async fn read_entries(&mut self) -> Result<()>
where T: Decode + std::fmt::Debug
{
@ -113,6 +114,12 @@ trait CursorWithStoreHeader<T>: PrimitiveCursor<T> {
println!("END of entries.");
Ok(())
}
async fn read_all_bytes(&mut self) -> std::result::Result<Vec<u8>, std::io::Error> {
let mut bytes: Vec<u8> = vec![];
self.file().read_to_end(&mut bytes).await?;
Ok(bytes)
}
}
@ -189,6 +196,10 @@ impl <T> ReadCursor<T> {
Ok(cursor)
}
pub async fn less_than_eq(&mut self, file_position0: FilePosition, file_position1: FilePosition) -> Result<bool> {
todo!()
}
}
impl <'cursor, T> WriteCursor<'cursor, T> {
@ -300,3 +311,23 @@ impl <'cursor, T> WriteCursor<'cursor, T> {
}
}
}
// TODO
// pub async fn search_for(&mut self, index: T) -> Result<()>
// where T: Send
// {
// // let index = self.primary_index.borrow_mut();
// // let x = index.lookup(self, 123).await?;
// todo!()
// }
// pub async fn search_for_entry_with_id(&mut self, id: T) -> Result<Option<EntryDetailed<T>>> {
// // TODO: make call to the primary index
// todo!()
// }
// // TODO: This needs to be some sort of an iterator
// pub async fn get_all_eq(&self, column: Column, value: T) -> Result<Option<EntryDetailed<T>>> {
// todo!()
// }