1
Fork 0
mirror of https://github.com/RGBCube/embd-rs synced 2025-07-26 21:17:44 +00:00

Readability improvements

This commit is contained in:
RGBCube 2024-01-04 23:35:02 +03:00
parent d7f67fcf4c
commit da1f20a409
No known key found for this signature in database

View file

@ -8,26 +8,14 @@ use std::{
#[doc(hidden)] #[doc(hidden)]
pub fn __string_runtime(neighbor: &str, path: &str) -> String { pub fn __string_runtime(neighbor: &str, path: &str) -> String {
let base = Path::new(neighbor) let file = Path::new(neighbor)
.parent() .parent()
.expect("Failed to get the parent of file"); .expect("Failed to get the parent of file")
.join(path);
let file = base.join(path);
fs::read_to_string(file).expect("Failed to read file") fs::read_to_string(file).expect("Failed to read file")
} }
#[doc(hidden)]
pub fn __bytes_runtime(neighbor: &str, path: &str) -> Vec<u8> {
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, /// Embed a files contents as a &str on release,
/// read from the filesystem as a String on debug. /// 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<u8> {
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, /// Embed a files contents as a &[u8] on release,
/// read from the filesystem as a Vec<u8> on debug. /// read from the filesystem as a Vec<u8> on debug.
/// ///
@ -122,10 +120,10 @@ pub struct File {
pub path: Cow<'static, Path>, pub path: Cow<'static, Path>,
} }
fn read_dir(path: &Path) -> Vec<DirEntry> { fn read_dir(directory: &Path) -> Vec<DirEntry> {
let mut entries = Vec::new(); 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 entry = entry.expect("Failed to read entry");
let filetype = entry.file_type().expect("Failed to read entry filetype"); let filetype = entry.file_type().expect("Failed to read entry filetype");
@ -153,11 +151,9 @@ fn read_dir(path: &Path) -> Vec<DirEntry> {
#[doc(hidden)] #[doc(hidden)]
pub fn __dir_runtime(neighbor: &str, path: &str) -> Dir { pub fn __dir_runtime(neighbor: &str, path: &str) -> Dir {
let base = Path::new(neighbor) let directory = Path::new(neighbor)
.parent() .parent()
.expect("Failed to get the parent of file"); .expect("Failed to get the parent of file")
let directory = base
.join(path) .join(path)
.canonicalize() .canonicalize()
.expect("Failed to canonicalize path"); .expect("Failed to canonicalize path");