minor refactoring and fixes
This commit is contained in:
parent
e98001f4a4
commit
3dc39edcab
2 changed files with 11 additions and 16 deletions
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ureq::http::StatusCode;
|
use ureq::http::{HeaderValue, StatusCode};
|
||||||
|
|
||||||
use super::{Alias, FileUploading, Share, SharryAlias, SharryFile};
|
use super::{Alias, FileUploading, Share, SharryAlias, SharryFile};
|
||||||
|
|
||||||
|
|
@ -68,19 +68,11 @@ impl FileChecked {
|
||||||
impl<'t> SharryFile<'t> for FileChecked {
|
impl<'t> SharryFile<'t> for FileChecked {
|
||||||
/// get a reference to the file's name
|
/// 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 {
|
fn name(&'t self) -> &'t str {
|
||||||
<Self as SharryFile>::extract_file_name(&self.path)
|
<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
|
fn size<T>(&self) -> T
|
||||||
where
|
where
|
||||||
T: TryFrom<usize>,
|
T: TryFrom<usize>,
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
path::{Path, PathBuf},
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait SharryFile<'t> {
|
pub trait SharryFile<'t> {
|
||||||
/// get a reference to the filename from a PathBuf reference
|
/// extract the filename part of a `Path` reference
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Expects `Path::file_name` and `ffi::OsStr::to_str` to succeed on the contained path.
|
/// Expects `path::Path::file_name` and `ffi::OsStr::to_str` to succeed on the given path
|
||||||
fn extract_file_name(p: &'t PathBuf) -> &'t str {
|
fn extract_file_name(p: &'t Path) -> &'t 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")
|
||||||
|
|
@ -32,7 +32,7 @@ pub trait SharryFile<'t> {
|
||||||
<T as TryInto<usize>>::Error: Debug + Display,
|
<T as TryInto<usize>>::Error: Debug + Display,
|
||||||
{
|
{
|
||||||
val.try_into()
|
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()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +41,10 @@ pub trait SharryFile<'t> {
|
||||||
fn offset<T>(&self) -> T
|
fn offset<T>(&self) -> T
|
||||||
where
|
where
|
||||||
T: TryFrom<usize>,
|
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
|
fn size<T>(&self) -> T
|
||||||
where
|
where
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue