elided lifetimes

This commit is contained in:
Jörn-Michael Miehe 2025-07-03 18:35:50 +00:00
parent 0efde0e134
commit 7e4bd398c2
4 changed files with 10 additions and 18 deletions

View file

@ -57,10 +57,7 @@ impl CacheFile {
}; };
if args.should_hash() { if args.should_hash() {
fn check_hash<'a>( fn check_hash(file: &impl FileTrait, bar: &ProgressBar) -> crate::Result<()> {
file: &'a impl FileTrait<'a>,
bar: &ProgressBar,
) -> crate::Result<()> {
bar.set_message(format!("checking {:?}", file.get_name())); bar.set_message(format!("checking {:?}", file.get_name()));
file.check_hash(|bytes| bar.inc(bytes)) file.check_hash(|bytes| bar.inc(bytes))
} }

View file

@ -85,11 +85,8 @@ impl Checked {
} }
} }
impl<'t> FileTrait<'t> for Checked { impl FileTrait for Checked {
/// get a reference to the file's name fn get_name(&self) -> &str {
///
/// Uses `SharryFile::extract_file_name`, which may **panic**!
fn get_name(&'t self) -> &'t str {
<Self as FileTrait>::extract_file_name(&self.path) <Self as FileTrait>::extract_file_name(&self.path)
} }

View file

@ -12,7 +12,6 @@ pub use chunk::Chunk;
use log::{debug, warn}; use log::{debug, warn};
pub use uploading::Uploading; pub use uploading::Uploading;
fn compute_file_hash(path: &Path, size: u64, on_progress: impl Fn(u64)) -> crate::Result<String> { fn compute_file_hash(path: &Path, size: u64, on_progress: impl Fn(u64)) -> crate::Result<String> {
let mut file = fs::File::open(path)?; let mut file = fs::File::open(path)?;
let mut hasher = Blake2b::new().hash_length(64).to_state(); let mut hasher = Blake2b::new().hash_length(64).to_state();
@ -61,20 +60,22 @@ fn check_file_hash(
} }
} }
pub trait FileTrait<'t> { pub trait FileTrait {
/// extract the filename part of a `Path` reference /// extract the filename part of a `Path` reference
/// ///
/// # Panics /// # Panics
/// ///
/// Expects `path::Path::file_name` and `ffi::OsStr::to_str` to succeed on the given path /// 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 { fn extract_file_name(p: &Path) -> &str {
p.file_name() p.file_name()
.and_then(OsStr::to_str) .and_then(OsStr::to_str)
.expect("bad file name") .expect("bad file name")
} }
/// get a reference to the file's name /// get a reference to the file's name
fn get_name(&'t self) -> &'t str; ///
/// Uses `file::FileTrait::extract_file_name`, which may **panic**!
fn get_name(&self) -> &str;
/// get the file's size /// get the file's size
fn get_size(&self) -> u64; fn get_size(&self) -> u64;

View file

@ -94,11 +94,8 @@ impl Uploading {
} }
} }
impl<'t> FileTrait<'t> for Uploading { impl FileTrait for Uploading {
/// get a reference to the file's name fn get_name(&self) -> &str {
///
/// Uses `SharryFile::extract_file_name`, which may **panic**!
fn get_name(&'t self) -> &'t str {
<Self as FileTrait>::extract_file_name(&self.path) <Self as FileTrait>::extract_file_name(&self.path)
} }