From 3dc39edcabbe2fd40a13429f32ca9c5fd9ab982a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Fri, 6 Jun 2025 22:25:39 +0000 Subject: [PATCH] minor refactoring and fixes --- src/sharry/file/checked.rs | 12 ++---------- src/sharry/file/filetrait.rs | 15 +++++++++------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/sharry/file/checked.rs b/src/sharry/file/checked.rs index 8df0d86..2d80026 100644 --- a/src/sharry/file/checked.rs +++ b/src/sharry/file/checked.rs @@ -6,7 +6,7 @@ use std::{ use log::debug; use serde::{Deserialize, Serialize}; -use ureq::http::StatusCode; +use ureq::http::{HeaderValue, StatusCode}; use super::{Alias, FileUploading, Share, SharryAlias, SharryFile}; @@ -68,19 +68,11 @@ impl FileChecked { impl<'t> SharryFile<'t> for FileChecked { /// get a reference to the file's name /// - /// Uses SharryFile::extract_file_name, which may **panic**! + /// Uses `SharryFile::extract_file_name`, which may **panic**! fn name(&'t self) -> &'t str { ::extract_file_name(&self.path) } - fn offset(&self) -> T - where - T: TryFrom, - >::Error: std::fmt::Debug + std::fmt::Display, - { - ::from_usize(0) - } - fn size(&self) -> T where T: TryFrom, diff --git a/src/sharry/file/filetrait.rs b/src/sharry/file/filetrait.rs index 848a620..b466d58 100644 --- a/src/sharry/file/filetrait.rs +++ b/src/sharry/file/filetrait.rs @@ -1,16 +1,16 @@ use std::{ ffi::OsStr, fmt::{Debug, Display}, - path::{Path, PathBuf}, + path::Path, }; pub trait SharryFile<'t> { - /// get a reference to the filename from a PathBuf reference + /// extract the filename part of a `Path` reference /// /// # Panics /// - /// Expects `Path::file_name` and `ffi::OsStr::to_str` to succeed on the contained path. - fn extract_file_name(p: &'t PathBuf) -> &'t str { + /// Expects `path::Path::file_name` and `ffi::OsStr::to_str` to succeed on the given path + fn extract_file_name(p: &'t Path) -> &'t str { p.file_name() .and_then(OsStr::to_str) .expect("bad file name") @@ -32,7 +32,7 @@ pub trait SharryFile<'t> { >::Error: Debug + Display, { val.try_into() - .inspect_err(|e| panic!("usize did not fit into other type: {e}")) + .inspect_err(|e| panic!("other type did not fit into usize: {e}")) .unwrap() } @@ -41,7 +41,10 @@ pub trait SharryFile<'t> { fn offset(&self) -> T where T: TryFrom, - >::Error: Debug + Display; + >::Error: Debug + Display, + { + Self::from_usize(0) + } fn size(&self) -> T where