mirror of
https://github.com/RGBCube/embd-rs
synced 2025-07-26 04:57:44 +00:00
Improve docs and add DirEntry::path
This commit is contained in:
parent
ccd617123a
commit
8f3c415308
1 changed files with 17 additions and 7 deletions
|
@ -14,14 +14,14 @@ pub fn __string_runtime(neighbor: &str, path: &str) -> String {
|
||||||
fs::read_to_string(file).expect("Failed to read file")
|
fs::read_to_string(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.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let content = embed::string!("main.rs");
|
/// let content: Cow<'static, str> = embed::string!("main.rs");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -48,15 +48,15 @@ pub fn __bytes_runtime(neighbor: &str, path: &str) -> Vec<u8> {
|
||||||
fs::read(file).expect("Failed to read file")
|
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.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// // `assets/` is in the same directory as `src/`
|
/// // `assets/` is in the same directory as `src/`
|
||||||
/// let content = embed::string!("../assets/icon.png");
|
/// let content: Cow<'static, [u8]> = embed::string!("../assets/icon.png");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -82,6 +82,16 @@ pub enum DirEntry {
|
||||||
File(File),
|
File(File),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DirEntry {
|
||||||
|
/// Returns the absolute path of the entry.
|
||||||
|
pub fn path(&self) -> &Path {
|
||||||
|
match self {
|
||||||
|
DirEntry::File(file) => file.path(),
|
||||||
|
DirEntry::Dir(dir) => dir.path(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A directory.
|
/// A directory.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Dir {
|
pub struct Dir {
|
||||||
|
@ -208,7 +218,7 @@ pub fn __dir_runtime(neighbor: &str, path: &str) -> Dir {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let content = embed::dir!("../assets");
|
/// let content: embed::Dir = embed::dir!("../assets");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub use embed_macros::__dir as dir;
|
pub use embed_macros::__dir as dir;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue