mirror of
https://github.com/RGBCube/embd-rs
synced 2025-07-27 05:27:44 +00:00
Use Cow. Moo
This commit is contained in:
parent
f2b0e744c4
commit
6c33b6177d
2 changed files with 4 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
#![cfg(procmacro2_semver_exempt)]
|
#![cfg(procmacro2_semver_exempt)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
fs,
|
fs,
|
||||||
path::{
|
path::{
|
||||||
Path,
|
Path,
|
||||||
|
@ -119,7 +120,7 @@ impl Dir {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
/// The content of the file in bytes.
|
/// The content of the file in bytes.
|
||||||
pub content: Vec<u8>,
|
pub content: Cow<'static, [u8]>,
|
||||||
/// The absolute path of the file.
|
/// The absolute path of the file.
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -149,7 +150,7 @@ fn read_dir(path: &PathBuf) -> Vec<DirEntry> {
|
||||||
|
|
||||||
entries.push(DirEntry::Dir(Dir { children, path }))
|
entries.push(DirEntry::Dir(Dir { children, path }))
|
||||||
} else if filetype.is_file() {
|
} else if filetype.is_file() {
|
||||||
let content = fs::read(&path).expect("Failed to read file contents");
|
let content = Cow::Owned(fs::read(&path).expect("Failed to read file contents"));
|
||||||
|
|
||||||
entries.push(DirEntry::File(File { content, path }))
|
entries.push(DirEntry::File(File { content, path }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ fn read_dir(directory: &PathBuf) -> Vec<DirEntry> {
|
||||||
} else if filetype.is_file() {
|
} else if filetype.is_file() {
|
||||||
entries.push(quote! {
|
entries.push(quote! {
|
||||||
::embed::DirEntry::File(::embed::File {
|
::embed::DirEntry::File(::embed::File {
|
||||||
content: include_bytes!(#path_str).to_vec(),
|
content: ::std::borrow::Cow::Borrowed(include_bytes!(#path_str)),
|
||||||
path: #path,
|
path: #path,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue