fix(lints): apply clippy suggestions

This commit is contained in:
Orhun Parmaksız 2022-02-24 23:54:54 +03:00
parent 3cc40deca0
commit 6f1dcab15a
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90
4 changed files with 6 additions and 11 deletions

View File

@ -11,7 +11,7 @@ pub const EXPIRE: &str = "expire";
/// Parses the expiry date from the [`custom HTTP header`](EXPIRE). /// Parses the expiry date from the [`custom HTTP header`](EXPIRE).
pub fn parse_expiry_date(headers: &HeaderMap) -> Result<Option<u128>, ActixError> { pub fn parse_expiry_date(headers: &HeaderMap) -> Result<Option<u128>, ActixError> {
if let Some(expire_time) = headers.get(EXPIRE).map(|v| v.to_str().ok()).flatten() { if let Some(expire_time) = headers.get(EXPIRE).and_then(|v| v.to_str().ok()) {
let timestamp = util::get_system_time()?; let timestamp = util::get_system_time()?;
let expire_time = let expire_time =
humantime::parse_duration(expire_time).map_err(error::ErrorInternalServerError)?; humantime::parse_duration(expire_time).map_err(error::ErrorInternalServerError)?;
@ -57,8 +57,7 @@ impl ContentDisposition {
.parameters .parameters
.iter() .iter()
.find(|param| param.is_filename()) .find(|param| param.is_filename())
.map(|param| param.as_filename()) .and_then(|param| param.as_filename())
.flatten()
.filter(|file_name| !file_name.is_empty()) .filter(|file_name| !file_name.is_empty())
.ok_or_else(|| error::ErrorBadRequest("file data not present")) .ok_or_else(|| error::ErrorBadRequest("file data not present"))
} }

View File

@ -25,8 +25,7 @@ pub fn get_mime_type(
let path = PathBuf::from(&file_name); let path = PathBuf::from(&file_name);
let mut mime_type = file_extension_to_mime( let mut mime_type = file_extension_to_mime(
path.extension() path.extension()
.map(|v| v.to_str()) .and_then(|v| v.to_str())
.flatten()
.unwrap_or_default(), .unwrap_or_default(),
); );
for matcher in mime_matchers { for matcher in mime_matchers {

View File

@ -104,8 +104,7 @@ impl Paste {
} }
let file_name = match PathBuf::from(file_name) let file_name = match PathBuf::from(file_name)
.file_name() .file_name()
.map(|v| v.to_str()) .and_then(|v| v.to_str())
.flatten()
{ {
Some("-") => String::from("stdin"), Some("-") => String::from("stdin"),
Some(v) => v.to_string(), Some(v) => v.to_string(),

View File

@ -39,10 +39,8 @@ pub fn glob_match_file(mut path: PathBuf) -> Result<PathBuf, ActixError> {
let glob_path = glob_path.map_err(error::ErrorInternalServerError)?; let glob_path = glob_path.map_err(error::ErrorInternalServerError)?;
if let Some(extension) = glob_path if let Some(extension) = glob_path
.extension() .extension()
.map(|v| v.to_str()) .and_then(|v| v.to_str())
.flatten() .and_then(|v| v.parse().ok())
.map(|v| v.parse().ok())
.flatten()
{ {
if get_system_time()? < Duration::from_millis(extension) { if get_system_time()? < Duration::from_millis(extension) {
path = glob_path; path = glob_path;