From de07d556a2cbac68db198dd0ff91bdc6936f85a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Wed, 18 Jun 2025 13:04:04 +0000 Subject: [PATCH] minor refactoring - `use crate::` where appropriate - cleanup CLI parsing - `Uri::with_protocol` -> `Uri::new` --- notes.md | 1 + src/appstate.rs | 2 +- src/cachefile.rs | 2 +- src/cli.rs | 12 +++++++----- src/sharry/api.rs | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/notes.md b/notes.md index cec706c..670ab4b 100644 --- a/notes.md +++ b/notes.md @@ -55,6 +55,7 @@ - client error rework - current variants are too "low level" - use variants like `InvalidEndpoint`, `InvalidAlias` etc. + - `Uploading::abort() -> Checked` - hashing - store file hashes with all `file::*` variants diff --git a/src/appstate.rs b/src/appstate.rs index 955ea02..f91bef3 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -8,7 +8,7 @@ use console::style; use indicatif::{ProgressBar, ProgressStyle}; use log::{debug, warn}; -use super::{ +use crate::{ cachefile::CacheFile, cli::Cli, file::{self, Chunk, FileTrait}, diff --git a/src/cachefile.rs b/src/cachefile.rs index 98cf19a..3fc01c1 100644 --- a/src/cachefile.rs +++ b/src/cachefile.rs @@ -8,7 +8,7 @@ use std::{ use log::trace; use serde::{Deserialize, Serialize}; -use super::{ +use crate::{ cli::Cli, file::{self, FileTrait}, sharry::{self, Client, Uri}, diff --git a/src/cli.rs b/src/cli.rs index b0f470e..4742995 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,8 @@ use std::{ + convert::Infallible, fmt, hash::{DefaultHasher, Hash, Hasher}, + io, time::Duration, }; @@ -10,7 +12,7 @@ use clap::{ value_parser, }; -use super::{ +use crate::{ file::Checked, sharry::{NewShareRequest, Uri}, }; @@ -79,12 +81,12 @@ impl fmt::Debug for Cli { } } -fn parse_seconds(data: &str) -> Result { +fn parse_seconds(data: &str) -> Result { data.parse().or(Ok(0)).map(Duration::from_secs) } -fn parse_sharry_file(data: &str) -> Result { - Checked::new(data).map_err(|e| e.to_string()) +fn parse_sharry_file(data: &str) -> io::Result { + Checked::new(data) } impl Cli { @@ -93,7 +95,7 @@ impl Cli { } pub fn get_uri(&self) -> Uri { - Uri::with_protocol(&self.protocol, &self.url) + Uri::new(&self.protocol, &self.url) } pub fn get_share_request(&self) -> NewShareRequest { diff --git a/src/sharry/api.rs b/src/sharry/api.rs index 3658b9a..c1cb5f3 100644 --- a/src/sharry/api.rs +++ b/src/sharry/api.rs @@ -10,7 +10,7 @@ pub struct Uri { } impl Uri { - pub fn with_protocol(protocol: impl Into, base_url: impl Into) -> Self { + pub fn new(protocol: impl Into, base_url: impl Into) -> Self { Self { protocol: protocol.into(), base_url: base_url.into(),