Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Maneren committed Nov 26, 2023
1 parent 44a2ce8 commit d972b49
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/fileserv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn handle_archive_with_path(
Path(path): Path<String>,
Query(params): Query<HashMap<String, String>>,
) -> impl IntoResponse {
eprintln!("path: {:?}", path);
eprintln!("path: {path:?}");
handle_archive(params.get("method"), path)
}

Expand Down
11 changes: 4 additions & 7 deletions src/fileserv/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,9 @@ where
{
let name = basename(base_path, path)?;

zip.start_file(&name, FileOptions::default()).map_err(|e| {
Error::Io(
format!("Failed to add {} to the ZIP archive", name),
e.into(),
)
})?;
zip
.start_file(&name, FileOptions::default())
.map_err(|e| Error::Io(format!("Failed to add {name} to the ZIP archive"), e.into()))?;

let mut file = fs::File::open(path).map_err(|e| {
Error::Io(
Expand All @@ -231,7 +228,7 @@ where
})?;

io::copy(&mut file, zip)
.map_err(|e| Error::Io(format!("Failed to write {} to the ZIP archive", name), e))?;
.map_err(|e| Error::Io(format!("Failed to write {name} to the ZIP archive"), e))?;

Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::must_use_candidate)]
#![feature(generic_arg_infer)]

use cfg_if::cfg_if;
pub mod app;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/files/components/file_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub struct Entry {
last_modified: SystemTime,
relative_time: String,
}
#[allow(clippy::needless_lifetimes)]

#[allow(clippy::needless_pass_by_value)]
#[component]
pub fn Icon(icon: String) -> impl IntoView {
view! { <img class="icon h-10 w-10" src=format!("/icons/{icon}.svg") alt=format!("{icon} icon")/> }
Expand Down
7 changes: 4 additions & 3 deletions src/pages/files/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub enum ServerEntry {

#[server]
pub async fn list_dir(path: PathBuf) -> Result<Entries, ServerFnError> {
use crate::config::get_target_dir;

if path.is_absolute() {
return Err(ServerFnError::ServerError("Path must be relative".into()));
}
Expand All @@ -32,7 +34,6 @@ pub async fn list_dir(path: PathBuf) -> Result<Entries, ServerFnError> {
));
}

use crate::config::get_target_dir;
let Ok(path) = get_target_dir().join(path).canonicalize() else {
return Err(ServerFnError::ServerError(
"Path must be inside target_dir".into(),
Expand All @@ -52,13 +53,13 @@ pub async fn list_dir(path: PathBuf) -> Result<Entries, ServerFnError> {
entries.push(ServerEntry::Folder {
name,
last_modified,
})
});
} else if metadata.is_file() {
entries.push(ServerEntry::File {
name,
size: metadata.len(),
last_modified,
})
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/files/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub fn get_file_icon(name: &str) -> String {
.get(&extension)
.unwrap_or(&extension_str);

if KNOWN_EXTENSIONS.contains(&extension) {
extension.to_string()
if KNOWN_EXTENSIONS.contains(extension) {
(*extension).to_string()
} else {
"file".into()
}
Expand Down

0 comments on commit d972b49

Please sign in to comment.