minor refactoring and fixes

This commit is contained in:
Jörn-Michael Miehe 2025-06-06 22:25:39 +00:00
parent e98001f4a4
commit 3dc39edcab
2 changed files with 11 additions and 16 deletions

View file

@ -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 {
<Self as SharryFile>::extract_file_name(&self.path)
}
fn offset<T>(&self) -> T
where
T: TryFrom<usize>,
<T as TryFrom<usize>>::Error: std::fmt::Debug + std::fmt::Display,
{
<Self as SharryFile>::from_usize(0)
}
fn size<T>(&self) -> T
where
T: TryFrom<usize>,

View file

@ -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> {
<T as TryInto<usize>>::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<T>(&self) -> T
where
T: TryFrom<usize>,
<T as TryFrom<usize>>::Error: Debug + Display;
<T as TryFrom<usize>>::Error: Debug + Display,
{
Self::from_usize(0)
}
fn size<T>(&self) -> T
where