Split Store into Store and Cursor
This commit is contained in:
parent
dbd2ba9946
commit
3e7e8665fd
2 changed files with 252 additions and 203 deletions
|
|
@ -23,11 +23,12 @@ async fn create_store() -> Result<Store<Data>> {
|
|||
println!("THE STORE: {:?}", store);
|
||||
println!("THE BYTES: {:?}", store.read_all_bytes().await?);
|
||||
|
||||
let mut cursor = store.cursor(AccessMode::Write).await.map_err(|e| e.to_io_or_panic())?;
|
||||
let entry0: Entry<u32> = Entry::new_deleted(vec![1, 2, 3, 4, 5]);
|
||||
append_entry(&mut store, &entry0).await?;
|
||||
append_entry(&mut cursor, &entry0).await?;
|
||||
|
||||
let entry1: Entry<u32> = Entry::new_deleted(vec![200, 200, 5, 6, 7]);
|
||||
append_entry(&mut store, &entry1).await?;
|
||||
append_entry(&mut cursor, &entry1).await?;
|
||||
|
||||
println!("{:?}", store.read_all_bytes().await?);
|
||||
Ok(store)
|
||||
|
|
@ -51,17 +52,17 @@ async fn create_or_connect() -> Result<Store<Data>> {
|
|||
}
|
||||
|
||||
|
||||
async fn append_entry(store: &mut Store<Data>, entry: &Entry<Data>) -> Result<FilePosition>{
|
||||
async fn append_entry(cursor: &mut Cursor<Data>, entry: &Entry<Data>) -> Result<FilePosition>{
|
||||
println!("APPENDING");
|
||||
println!("entry == {:?}", entry);
|
||||
let file_position: FilePosition = store.append_entry(&entry).await.map_err(|e| e.to_io_or_panic())?;
|
||||
let file_position: FilePosition = cursor.append_entry(&entry).await.map_err(|e| e.to_io_or_panic())?;
|
||||
println!("file_position == {:?}", file_position);
|
||||
Ok(file_position)
|
||||
}
|
||||
|
||||
async fn read_entry(store: &mut Store<Data>, file_position: FilePosition) -> Result<Option<EntryDetailed<Data>>>{
|
||||
async fn read_entry(cursor: &mut Cursor<Data>, file_position: FilePosition) -> Result<Option<EntryDetailed<Data>>>{
|
||||
println!("READING ENTRY at file_position={}", file_position);
|
||||
let entry = store.read_entry_at(file_position).await.map_err(|e| e.to_io_or_panic())?;
|
||||
let entry = cursor.read_entry_at(file_position).await.map_err(|e| e.to_io_or_panic())?;
|
||||
println!("ENTRY: {:?}", entry);
|
||||
Ok(entry)
|
||||
}
|
||||
|
|
@ -71,17 +72,18 @@ async fn read_entry(store: &mut Store<Data>, file_position: FilePosition) -> Res
|
|||
async fn main() -> Result<()> {
|
||||
println!("STOOOOOOOOOOOORAAAAAAAAAAAGE");
|
||||
|
||||
let mut store: Store<Data> = create_or_connect().await?;
|
||||
let store: Store<Data> = create_or_connect().await?;
|
||||
|
||||
// let entry0 = read_entry(&mut store, 16).await?;
|
||||
// let entry1 = read_entry(&mut store, 45).await?;
|
||||
// println!("{:?}", store);
|
||||
// println!("{:?}", store.read_all_bytes().await?);
|
||||
|
||||
let mut cursor = store.cursor(AccessMode::Write).await.map_err(|e| e.to_io_or_panic())?;
|
||||
let entry0: Entry<u32> = Entry::new(vec![99, 98, 97, 96, 95]);
|
||||
append_entry(&mut store, &entry0).await?;
|
||||
append_entry(&mut cursor, &entry0).await?;
|
||||
|
||||
store.read_entries().await.map_err(|e| e.to_io_or_panic())?;
|
||||
cursor.read_entries().await.map_err(|e| e.to_io_or_panic())?;
|
||||
|
||||
|
||||
// let entry2: StoreEntry<u32> = StoreEntry::new_deleted(vec![3, 2, 1]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue