Rename cursor ~> file_position
This commit is contained in:
parent
cac34d95e0
commit
28741006e7
2 changed files with 81 additions and 46 deletions
|
|
@ -20,7 +20,8 @@ type Result<T> = std::result::Result<T, std::io::Error>;
|
|||
async fn create_store() -> Result<Store<Data>> {
|
||||
let mut store: Store<Data> = Store::new(TABLE_PATH, 5, 0).await.map_err(|e| e.to_io_or_panic())?;
|
||||
println!("CREATED");
|
||||
println!("{:?}", store.read_all_bytes().await?);
|
||||
println!("THE STORE: {:?}", store);
|
||||
println!("THE BYTES: {:?}", store.read_all_bytes().await?);
|
||||
|
||||
let entry0: Entry<u32> = Entry::new_deleted(vec![1, 2, 3, 4, 5]);
|
||||
append_entry(&mut store, &entry0).await?;
|
||||
|
|
@ -31,10 +32,12 @@ async fn create_store() -> Result<Store<Data>> {
|
|||
println!("{:?}", store.read_all_bytes().await?);
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
async fn connect_store() -> Result<Store<Data>> {
|
||||
let mut store: Store<Data> = Store::connect(TABLE_PATH).await.map_err(|e| e.to_io_or_panic())?;
|
||||
println!("CONNECTED");
|
||||
println!("{:?}", store.read_all_bytes().await?);
|
||||
println!("THE STORE: {:?}", store);
|
||||
println!("THE BYTES: {:?}", store.read_all_bytes().await?);
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
|
|
@ -48,17 +51,17 @@ async fn create_or_connect() -> Result<Store<Data>> {
|
|||
}
|
||||
|
||||
|
||||
async fn append_entry(store: &mut Store<Data>, entry: &Entry<Data>) -> Result<Cursor>{
|
||||
async fn append_entry(store: &mut Store<Data>, entry: &Entry<Data>) -> Result<FilePosition>{
|
||||
println!("APPENDING");
|
||||
println!("entry == {:?}", entry);
|
||||
let cursor: Cursor = store.append_entry(&entry).await.map_err(|e| e.to_io_or_panic())?;
|
||||
println!("cursor == {:?}", cursor);
|
||||
Ok(cursor)
|
||||
let file_position: FilePosition = store.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>, cursor: Cursor) -> Result<EntryDetailed<Data>>{
|
||||
println!("READING ENTRY at cursor={}", cursor);
|
||||
let entry = store.read_entry_at(cursor).await.map_err(|e| e.to_io_or_panic())?;
|
||||
async fn read_entry(store: &mut Store<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())?;
|
||||
println!("ENTRY: {:?}", entry);
|
||||
Ok(entry)
|
||||
}
|
||||
|
|
@ -75,10 +78,10 @@ async fn main() -> Result<()> {
|
|||
// println!("{:?}", store);
|
||||
// println!("{:?}", store.read_all_bytes().await?);
|
||||
|
||||
// let entry0: Entry<u32> = Entry::new(vec![99, 98, 97, 96, 95]);
|
||||
// append_entry(&mut store, &entry0).await?;
|
||||
let entry0: Entry<u32> = Entry::new(vec![99, 98, 97, 96, 95]);
|
||||
append_entry(&mut store, &entry0).await?;
|
||||
|
||||
store.read_entries(2).await.map_err(|e| e.to_io_or_panic())?;
|
||||
store.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