Merge branch 'develop' into feature/unit_tests
This commit is contained in:
commit
52d455e219
4 changed files with 8 additions and 11 deletions
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,8 +91,8 @@ impl Checked {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> FileTrait<'t> for Checked {
|
impl FileTrait for Checked {
|
||||||
fn get_name(&'t self) -> &'t str {
|
fn get_name(&self) -> &str {
|
||||||
<Self as FileTrait>::extract_file_name(&self.path)
|
<Self as FileTrait>::extract_file_name(&self.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,13 +96,13 @@ fn check_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")
|
||||||
|
|
@ -111,7 +111,7 @@ pub trait FileTrait<'t> {
|
||||||
/// get a reference to the file's name
|
/// get a reference to the file's name
|
||||||
///
|
///
|
||||||
/// Uses `file::FileTrait::extract_file_name`, which may **panic**!
|
/// Uses `file::FileTrait::extract_file_name`, which may **panic**!
|
||||||
fn get_name(&'t self) -> &'t str;
|
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;
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,8 @@ impl Uploading {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> FileTrait<'t> for Uploading {
|
impl FileTrait for Uploading {
|
||||||
fn get_name(&'t self) -> &'t str {
|
fn get_name(&self) -> &str {
|
||||||
<Self as FileTrait>::extract_file_name(&self.path)
|
<Self as FileTrait>::extract_file_name(&self.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue