From 28f182c4b197a9bfc6e24e17ca8de2eb9d9b645f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20Moravec?= Date: Sun, 4 Feb 2024 20:52:17 +0100 Subject: [PATCH] refactor: remove long uses --- storage_engine/src/index.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/storage_engine/src/index.rs b/storage_engine/src/index.rs index 5d2187a..b5c42c1 100644 --- a/storage_engine/src/index.rs +++ b/storage_engine/src/index.rs @@ -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(); } }