summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaz <ndpm13@ch-naseem.com>2025-07-31 15:46:40 +0100
committerNaz <ndpm13@ch-naseem.com>2025-07-31 15:46:40 +0100
commit29c3640e5fea0f423357c28e3c221fcaca004ee8 (patch)
treea7f774b1f58ccb3070fd3b0f7d3dad1e524bc40d
parentbd230c3d916be2af8f97e587f3f764800077cba4 (diff)
✨feat: use the custom Result type instead of the standard
-rw-r--r--src/downloader.rs8
-rw-r--r--src/index.rs12
-rw-r--r--src/main.rs4
-rw-r--r--src/manager.rs15
-rw-r--r--src/symlink.rs6
5 files changed, 17 insertions, 28 deletions
diff --git a/src/downloader.rs b/src/downloader.rs
index 2196e25..be35bd8 100644
--- a/src/downloader.rs
+++ b/src/downloader.rs
@@ -2,7 +2,7 @@ use futures_util::StreamExt;
use std::path::PathBuf;
use tokio::{fs, io::AsyncWriteExt};
-use crate::{appimages_dir, make_progress_bar};
+use crate::{Result, appimages_dir, make_progress_bar};
#[derive(Debug, Default)]
pub struct Downloader {}
@@ -20,11 +20,7 @@ impl Downloader {
appimages_dir().join(filename)
}
- pub async fn download_with_progress(
- &self,
- url: &str,
- path: &PathBuf,
- ) -> Result<(), Box<dyn std::error::Error>> {
+ pub async fn download_with_progress(&self, url: &str, path: &PathBuf) -> Result<()> {
fs::create_dir_all(&appimages_dir()).await?;
let resp = reqwest::get(&url.to_string()).await?;
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<AppImage, Box<dyn std::error::Error>> {
+ pub async fn get(&self, appname: &str) -> Result<AppImage> {
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<dyn std::error::Error>> {
+ 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<dyn std::error::Error>> {
+ 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?;
diff --git a/src/main.rs b/src/main.rs
index 1d9505b..b6d538e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,10 +2,10 @@ use std::path::PathBuf;
use clap::Parser;
-use zap_rs::{AppImage, Cli, Command, PackageManager, Source, SourceMetadata};
+use zap_rs::{AppImage, Cli, Command, PackageManager, Result, Source, SourceMetadata};
#[tokio::main]
-async fn main() -> Result<(), Box<dyn std::error::Error>> {
+async fn main() -> Result<()> {
let args = Cli::parse();
let pm = PackageManager::new();
diff --git a/src/manager.rs b/src/manager.rs
index 66ed6f6..6616e1a 100644
--- a/src/manager.rs
+++ b/src/manager.rs
@@ -1,6 +1,6 @@
use tokio::fs;
-use crate::{AppImage, Downloader, Index, SymlinkManager, index_dir};
+use crate::{AppImage, Downloader, Index, Result, SymlinkManager, index_dir};
#[derive(Debug, Default)]
pub struct PackageManager {
@@ -17,13 +17,10 @@ impl PackageManager {
symlink_manager: SymlinkManager::new(),
}
}
- pub async fn install(
- &self,
- appimage: &mut AppImage,
- appname: &str,
- ) -> Result<(), Box<dyn std::error::Error>> {
+ pub async fn install(&self, appimage: &mut AppImage, appname: &str) -> Result<()> {
if self.index.exists(&appimage.executable) {
- return Err(format!("{} is already installed.", &appimage.executable).into());
+ println!("{} is already installed.", appimage.executable);
+ return Ok(());
}
appimage.file_path = self
@@ -37,7 +34,7 @@ impl PackageManager {
self.symlink_manager.create(appimage).await?;
Ok(())
}
- pub async fn remove(&self, appname: &str) -> Result<(), Box<dyn std::error::Error>> {
+ pub async fn remove(&self, appname: &str) -> Result<()> {
let appimage = self.index.get(appname).await?;
fs::remove_file(&appimage.file_path).await?;
@@ -46,7 +43,7 @@ impl PackageManager {
Ok(())
}
- pub async fn list(&self) -> Result<(), Box<dyn std::error::Error>> {
+ pub async fn list(&self) -> Result<()> {
let mut appimages = fs::read_dir(index_dir()).await?;
while let Some(appimage) = appimages.next_entry().await? {
diff --git a/src/symlink.rs b/src/symlink.rs
index 843115c..68a804f 100644
--- a/src/symlink.rs
+++ b/src/symlink.rs
@@ -1,7 +1,7 @@
use std::path::PathBuf;
use tokio::fs;
-use crate::AppImage;
+use crate::{AppImage, Result};
#[derive(Debug, Default)]
pub struct SymlinkManager {}
@@ -10,7 +10,7 @@ impl SymlinkManager {
pub fn new() -> Self {
Self {}
}
- pub async fn remove(&self, executable: &str) -> Result<(), Box<dyn std::error::Error>> {
+ pub async fn remove(&self, executable: &str) -> Result<()> {
let home = std::env::var("HOME")?;
let symlink_path = PathBuf::from(home).join(".local/bin").join(executable);
@@ -18,7 +18,7 @@ impl SymlinkManager {
Ok(())
}
- pub async fn create(&self, appimage: &AppImage) -> Result<(), Box<dyn std::error::Error>> {
+ pub async fn create(&self, appimage: &AppImage) -> Result<()> {
let home = std::env::var("HOME")?;
let local_bin = PathBuf::from(home).join(".local/bin");