From 29c3640e5fea0f423357c28e3c221fcaca004ee8 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 31 Jul 2025 15:46:40 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20use=20the=20custom=20Result=20type=20i?= =?UTF-8?q?nstead=20of=20the=20standard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/index.rs') diff --git a/src/index.rs b/src/index.rs index 069068a..dff2f58 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1,6 +1,6 @@ use tokio::fs; -use crate::{AppImage, index_dir}; +use crate::{AppImage, Result, index_dir}; #[derive(Debug, Default)] pub struct Index {} @@ -9,7 +9,7 @@ impl Index { pub fn new() -> Self { Self {} } - pub async fn get(&self, appname: &str) -> Result> { + pub async fn get(&self, appname: &str) -> Result { let index_file_path = index_dir().join(format!("{appname}.json")); let index_file_content = fs::read_to_string(&index_file_path).await?; let appimage: AppImage = serde_json::from_str(&index_file_content)?; @@ -19,11 +19,7 @@ impl Index { pub fn exists(&self, executable: &str) -> bool { index_dir().join(format!("{}.json", &executable)).exists() } - pub async fn add( - &self, - appimage: &AppImage, - appname: &str, - ) -> Result<(), Box> { + pub async fn add(&self, appimage: &AppImage, appname: &str) -> Result<()> { fs::create_dir_all(&index_dir()).await?; let index_file = &index_dir().join(format!("{appname}.json")); @@ -33,7 +29,7 @@ impl Index { Ok(()) } - pub async fn remove(&self, appname: &str) -> Result<(), Box> { + pub async fn remove(&self, appname: &str) -> Result<()> { let index_file_path = index_dir().join(format!("{appname}.json")); fs::remove_file(index_file_path).await?; -- cgit v1.2.3 From 180fe06facf1f8b4796df69a42596643990b9d32 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 31 Jul 2025 15:59:56 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20remove=20expect=20from=20path=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/index.rs') diff --git a/src/index.rs b/src/index.rs index dff2f58..8f2521a 100644 --- a/src/index.rs +++ b/src/index.rs @@ -10,19 +10,19 @@ impl Index { Self {} } pub async fn get(&self, appname: &str) -> Result { - let index_file_path = index_dir().join(format!("{appname}.json")); + let index_file_path = index_dir()?.join(format!("{appname}.json")); let index_file_content = fs::read_to_string(&index_file_path).await?; let appimage: AppImage = serde_json::from_str(&index_file_content)?; Ok(appimage) } - pub fn exists(&self, executable: &str) -> bool { - index_dir().join(format!("{}.json", &executable)).exists() + pub fn exists(&self, executable: &str) -> Result { + Ok(index_dir()?.join(format!("{}.json", &executable)).exists()) } pub async fn add(&self, appimage: &AppImage, appname: &str) -> Result<()> { - fs::create_dir_all(&index_dir()).await?; + fs::create_dir_all(&index_dir()?).await?; - let index_file = &index_dir().join(format!("{appname}.json")); + let index_file = &index_dir()?.join(format!("{appname}.json")); let json = serde_json::to_string_pretty(appimage)?; fs::write(index_file, json).await?; @@ -30,7 +30,7 @@ impl Index { Ok(()) } pub async fn remove(&self, appname: &str) -> Result<()> { - let index_file_path = index_dir().join(format!("{appname}.json")); + let index_file_path = index_dir()?.join(format!("{appname}.json")); fs::remove_file(index_file_path).await?; Ok(()) -- cgit v1.2.3