From da1f20a40955d27a0fb1c4dae4596154d02fa640 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Thu, 4 Jan 2024 23:35:02 +0300 Subject: [PATCH] Readability improvements --- embed/src/lib.rs | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/embed/src/lib.rs b/embed/src/lib.rs index 9191761..4ebf700 100644 --- a/embed/src/lib.rs +++ b/embed/src/lib.rs @@ -8,26 +8,14 @@ use std::{ #[doc(hidden)] pub fn __string_runtime(neighbor: &str, path: &str) -> String { - let base = Path::new(neighbor) + let file = Path::new(neighbor) .parent() - .expect("Failed to get the parent of file"); - - let file = base.join(path); + .expect("Failed to get the parent of file") + .join(path); fs::read_to_string(file).expect("Failed to read file") } -#[doc(hidden)] -pub fn __bytes_runtime(neighbor: &str, path: &str) -> Vec { - let base = Path::new(neighbor) - .parent() - .expect("Failed to get the parent of file"); - - let file = base.join(path); - - fs::read(file).expect("Failed to read file") -} - /// Embed a files contents as a &str on release, /// read from the filesystem as a String on debug. /// @@ -54,6 +42,16 @@ macro_rules! string { }}; } +#[doc(hidden)] +pub fn __bytes_runtime(neighbor: &str, path: &str) -> Vec { + let file = Path::new(neighbor) + .parent() + .expect("Failed to get the parent of file") + .join(path); + + fs::read(file).expect("Failed to read file") +} + /// Embed a files contents as a &[u8] on release, /// read from the filesystem as a Vec on debug. /// @@ -122,10 +120,10 @@ pub struct File { pub path: Cow<'static, Path>, } -fn read_dir(path: &Path) -> Vec { +fn read_dir(directory: &Path) -> Vec { let mut entries = Vec::new(); - for entry in fs::read_dir(path).expect("Failed to list directory contents") { + for entry in fs::read_dir(directory).expect("Failed to list directory contents") { let entry = entry.expect("Failed to read entry"); let filetype = entry.file_type().expect("Failed to read entry filetype"); @@ -153,11 +151,9 @@ fn read_dir(path: &Path) -> Vec { #[doc(hidden)] pub fn __dir_runtime(neighbor: &str, path: &str) -> Dir { - let base = Path::new(neighbor) + let directory = Path::new(neighbor) .parent() - .expect("Failed to get the parent of file"); - - let directory = base + .expect("Failed to get the parent of file") .join(path) .canonicalize() .expect("Failed to canonicalize path");