refactor: remove long uses
This commit is contained in:
parent
a5c7306b90
commit
28f182c4b1
1 changed files with 13 additions and 11 deletions
|
|
@ -4,6 +4,7 @@ use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt, BufWriter};
|
|||
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::hash::Hash;
|
||||
use std::io::SeekFrom;
|
||||
|
||||
use crate::binary_coding::{decode, encode};
|
||||
use bincode;
|
||||
|
|
@ -80,7 +81,7 @@ where
|
|||
|
||||
pub async fn sync_to_disk(&mut self) -> Result<()> {
|
||||
let mut writer = BufWriter::new(&mut self.file);
|
||||
writer.seek(std::io::SeekFrom::Start(0)).await?;
|
||||
writer.seek(SeekFrom::Start(0)).await?;
|
||||
|
||||
let mut written: u64 = 0;
|
||||
let mut encoded = Vec::new();
|
||||
|
|
@ -104,7 +105,7 @@ where
|
|||
encoded.extend(encode(key)?);
|
||||
encoded.extend(encode(value)?);
|
||||
|
||||
self.file.seek(std::io::SeekFrom::End(0)).await?;
|
||||
self.file.seek(SeekFrom::End(0)).await?;
|
||||
self.file.write(&encoded).await?;
|
||||
|
||||
Ok(())
|
||||
|
|
@ -113,7 +114,7 @@ where
|
|||
async fn load_from_file(&mut self) -> Result<()> {
|
||||
let mut bytes = vec![];
|
||||
|
||||
self.file.seek(std::io::SeekFrom::Start(0)).await?;
|
||||
self.file.seek(SeekFrom::Start(0)).await?;
|
||||
self.file.read_to_end(&mut bytes).await?;
|
||||
|
||||
let mut cursor = 0;
|
||||
|
|
@ -135,12 +136,13 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tokio::fs::remove_file;
|
||||
|
||||
#[tokio::test]
|
||||
async fn connect_to_new() {
|
||||
let file_name = PathBuf::from("connect_to_new");
|
||||
if file_name.exists() {
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -153,14 +155,14 @@ mod tests {
|
|||
assert_eq!(index.data.len(), 0);
|
||||
}
|
||||
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn inserting() {
|
||||
let file_name = PathBuf::from("inserting");
|
||||
if file_name.exists() {
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -184,14 +186,14 @@ mod tests {
|
|||
assert_eq!(index.data.get(&2).unwrap().len(), 3);
|
||||
}
|
||||
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn lookuping() {
|
||||
let file_name = PathBuf::from("lookuping");
|
||||
if file_name.exists() {
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -235,14 +237,14 @@ mod tests {
|
|||
assert!(second.contains(&5));
|
||||
}
|
||||
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn deleting() {
|
||||
let file_name = PathBuf::from("deleting");
|
||||
if file_name.exists() {
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -278,6 +280,6 @@ mod tests {
|
|||
assert!(index.lookup(&2).await.unwrap().unwrap().contains(&5));
|
||||
}
|
||||
|
||||
tokio::fs::remove_file(&file_name).await.unwrap();
|
||||
remove_file(&file_name).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue