mirror of
https://github.com/RGBCube/embd-rs
synced 2025-07-26 21:17:44 +00:00
Rename to embd
This commit is contained in:
parent
7c2eb614db
commit
53f550c9c0
10 changed files with 86 additions and 91 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,10 +1,10 @@
|
||||||
*
|
*
|
||||||
|
|
||||||
!embed/
|
!embd/
|
||||||
!embed/src/
|
!embd/src/
|
||||||
|
|
||||||
!embed-macros/
|
!embd-macros/
|
||||||
!embed-macros/src/
|
!embd-macros/src/
|
||||||
|
|
||||||
!.gitignore
|
!.gitignore
|
||||||
|
|
||||||
|
|
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -3,14 +3,14 @@
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embed"
|
name = "embd"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embed-macros",
|
"embd-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embed-macros"
|
name = "embd-macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
@ -19,10 +19,21 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "embd-macros"
|
||||||
version = "1.0.76"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
|
checksum = "b3eb8e85bdd5a798ccdf92225a8e02f2b89f3ce547914842d54f6717e63eee59"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.78"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
@ -38,9 +49,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.48"
|
version = "2.0.50"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [ "embed", "embed-macros" ]
|
members = [ "embd", "embd-macros" ]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
29
README.md
29
README.md
|
@ -1,7 +1,7 @@
|
||||||
# embed-rs
|
# embd-rs
|
||||||
|
|
||||||
A super simple file and directory embedding crate,
|
A super simple file and directory embedding crate,
|
||||||
that loads files from the filesystem in debug mode,
|
that loads files from the filesystem on debug mode,
|
||||||
allowing for quick edit-and-test cycles without compilation.
|
allowing for quick edit-and-test cycles without compilation.
|
||||||
|
|
||||||
It is also super efficient, and does not heap allocate when the
|
It is also super efficient, and does not heap allocate when the
|
||||||
|
@ -16,24 +16,27 @@ Add this to your Cargo.toml:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embed = { git = "https://github.com/RGBCube/embed-rs" }
|
embd = "0.1"
|
||||||
|
|
||||||
[patch.crates-io]
|
|
||||||
proc-macro2 = { git = "https://github.com/RGBCube/proc-macro2" }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can use this crate as so:
|
Then you can use this crate like so:
|
||||||
|
|
||||||
```rs
|
```rs
|
||||||
let contents: Cow<'_, str> = embed::string!("path/to/file.txt");
|
let contents: Cow<'_, str> = embd::string!("path/to/file.txt");
|
||||||
let bytes: Cow<'_, [u8]> = embed::bytes!("path/to/image.png");
|
let bytes: Cow<'_, [u8]> = embd::bytes!("path/to/image.png");
|
||||||
|
|
||||||
let dir: embed::Dir = embed::dir!("path/to");
|
let dir: embd::Dir = embd::dir!("path/to");
|
||||||
let files: Vec<embed::File> = dir.flatten();
|
let files: Vec<embd::File> = dir.flatten();
|
||||||
```
|
```
|
||||||
|
|
||||||
I am not sure what name to publish this
|
Note that you will need to enable the `procmacro2_semver_exempt` feature
|
||||||
crate in, lmk if you find a good one.
|
to use this crate, you can enable it like so, by putting this in
|
||||||
|
`.cargo/config.toml` in the project root:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[build]
|
||||||
|
rustflags = [ "--cfg", "procmacro2_semver_exempt" ]
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "embed-macros"
|
name = "embd-macros"
|
||||||
description = "Read files or directories from the filesystem at runtime on debug, embed on release."
|
description = "Read files or directories from the filesystem at runtime on debug, embed on release."
|
||||||
repository = "https://github.com/RGBCube/embed-rs"
|
repository = "https://github.com/RGBCube/embd-rs"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
keywords = [ "embedding", "files", "debug-optimization", "bundling" ]
|
keywords = [ "embedding", "files", "debug-optimization", "bundling" ]
|
||||||
categories = [ "filesystem" ]
|
categories = [ "filesystem" ]
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![cfg(feature = "procmacro2_semver_exempt")]
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
path::Path,
|
path::Path,
|
||||||
|
@ -52,7 +53,7 @@ pub fn __dir(input: pm1::TokenStream) -> pm1::TokenStream {
|
||||||
|
|
||||||
fn dir_debug(path: &str) -> TokenStream {
|
fn dir_debug(path: &str) -> TokenStream {
|
||||||
quote! {
|
quote! {
|
||||||
::embed::__dir_runtime(file!(), #path)
|
::embd::__dir_runtime(file!(), #path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ fn dir_release(input: TokenStream, path: &str) -> TokenStream {
|
||||||
let children = read_dir(&directory);
|
let children = read_dir(&directory);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
::embed::Dir {
|
::embd::Dir {
|
||||||
__children: #children,
|
__children: #children,
|
||||||
__path: ::std::borrow::Cow::Borrowed(#directory_str),
|
__path: ::std::borrow::Cow::Borrowed(#directory_str),
|
||||||
}
|
}
|
||||||
|
@ -98,14 +99,14 @@ fn read_dir(directory: &Path) -> TokenVec {
|
||||||
let children = read_dir(&path);
|
let children = read_dir(&path);
|
||||||
|
|
||||||
entries.push(quote! {
|
entries.push(quote! {
|
||||||
::embed::DirEntry::Dir(::embed::Dir {
|
::embd::DirEntry::Dir(::embd::Dir {
|
||||||
__children: #children,
|
__children: #children,
|
||||||
__path: ::std::borrow::Cow::Borrowed(#path_str),
|
__path: ::std::borrow::Cow::Borrowed(#path_str),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
} else if filetype.is_file() {
|
} else if filetype.is_file() {
|
||||||
entries.push(quote! {
|
entries.push(quote! {
|
||||||
::embed::DirEntry::File(::embed::File {
|
::embd::DirEntry::File(::embd::File {
|
||||||
__content: ::std::borrow::Cow::Borrowed(include_bytes!(#path_str)),
|
__content: ::std::borrow::Cow::Borrowed(include_bytes!(#path_str)),
|
||||||
__path: ::std::borrow::Cow::Borrowed(#path_str),
|
__path: ::std::borrow::Cow::Borrowed(#path_str),
|
||||||
})
|
})
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "embed"
|
name = "embd"
|
||||||
description = "Read files or directories from the filesystem at runtime on debug, embed on release."
|
description = "Read files or directories from the filesystem at runtime on debug, embed on release."
|
||||||
repository = "https://github.com/RGBCube/embed-rs"
|
repository = "https://github.com/RGBCube/embd-rs"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
keywords = [ "embedding", "files", "debug-optimization", "bundling" ]
|
keywords = [ "embedding", "files", "debug-optimization", "bundling" ]
|
||||||
categories = [ "filesystem" ]
|
categories = [ "filesystem" ]
|
||||||
|
@ -10,4 +10,4 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embed-macros = { path = "../embed-macros" }
|
embd-macros = "0.1"
|
|
@ -1,19 +1,41 @@
|
||||||
# embed-rs
|
# embd-rs
|
||||||
|
|
||||||
A super simple file and directory embedding crate,
|
A super simple file and directory embedding crate,
|
||||||
that loads files from the filesystem in debug mode,
|
that loads files from the filesystem on debug mode,
|
||||||
allowing for quick edit-and-test cycles without compilation.
|
allowing for quick edit-and-test cycles without compilation.
|
||||||
|
|
||||||
|
It is also super efficient, and does not heap allocate when the
|
||||||
|
files are embedded on release mode by utilizing `std::borrow::Cow`.
|
||||||
|
|
||||||
On release mode it falls back to `include_str!`, `include_bytes!`
|
On release mode it falls back to `include_str!`, `include_bytes!`
|
||||||
and our own custom `include_dir!` implementation.
|
and our own custom `include_dir!`-like implementation.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```rs
|
Add this to your Cargo.toml:
|
||||||
let contents: Cow<'_, str> = embed::string!("path/to/file.txt");
|
|
||||||
let bytes: Cow<'_, [u8]> = embed::bytes!("path/to/image.png");
|
|
||||||
|
|
||||||
let dir: embed::Dir = embed::dir!("path/to");
|
```toml
|
||||||
|
[dependencies]
|
||||||
|
embd = "0.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can use this crate like so:
|
||||||
|
|
||||||
|
```rs
|
||||||
|
let contents: Cow<'_, str> = embd::string!("path/to/file.txt");
|
||||||
|
let bytes: Cow<'_, [u8]> = embd::bytes!("path/to/image.png");
|
||||||
|
|
||||||
|
let dir: embd::Dir = embd::dir!("path/to");
|
||||||
|
let files: Vec<embd::File> = dir.flatten();
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that you will need to enable the `procmacro2_semver_exempt` feature
|
||||||
|
to use this crate, you can enable it like so, by putting this in
|
||||||
|
`.cargo/config.toml` in the project root:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[build]
|
||||||
|
rustflags = [ "--cfg", "procmacro2_semver_exempt" ]
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![cfg(feature = "procmacro2_semver_exempt")]
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
fs,
|
fs,
|
||||||
|
@ -21,7 +22,7 @@ pub fn __string_runtime(neighbor: &str, path: &str) -> String {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let content: Cow<'static, str> = embed::string!("main.rs");
|
/// let content: Cow<'static, str> = embd::string!("main.rs");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -29,7 +30,7 @@ macro_rules! string {
|
||||||
($path:literal) => {{
|
($path:literal) => {{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
::std::borrow::Cow::Owned::<'static, str>(::embed::__string_runtime(file!(), $path))
|
::std::borrow::Cow::Owned::<'static, str>(::embd::__string_runtime(file!(), $path))
|
||||||
}
|
}
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
{
|
{
|
||||||
|
@ -56,7 +57,7 @@ pub fn __bytes_runtime(neighbor: &str, path: &str) -> Vec<u8> {
|
||||||
/// ```
|
/// ```
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// // `assets/` is in the same directory as `src/`
|
/// // `assets/` is in the same directory as `src/`
|
||||||
/// let content: Cow<'static, [u8]> = embed::string!("../assets/icon.png");
|
/// let content: Cow<'static, [u8]> = embd::string!("../assets/icon.png");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -64,7 +65,7 @@ macro_rules! bytes {
|
||||||
($path:literal) => {{
|
($path:literal) => {{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
::std::borrow::Cow::Owned::<'static, [u8]>(::embed::__bytes_runtime(file!(), $path))
|
::std::borrow::Cow::Owned::<'static, [u8]>(::embd::__bytes_runtime(file!(), $path))
|
||||||
}
|
}
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
{
|
{
|
||||||
|
@ -218,7 +219,7 @@ pub fn __dir_runtime(neighbor: &str, path: &str) -> Dir {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let content: embed::Dir = embed::dir!("../assets");
|
/// let content: embd::Dir = embd::dir!("../assets");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub use embed_macros::__dir as dir;
|
pub use embd_macros::__dir as dir;
|
|
@ -1,43 +0,0 @@
|
||||||
# embed-rs
|
|
||||||
|
|
||||||
A super simple file and directory embedding crate,
|
|
||||||
that loads files from the filesystem in debug mode,
|
|
||||||
allowing for quick edit-and-test cycles without compilation.
|
|
||||||
|
|
||||||
On release mode it falls back to `include_str!`, `include_bytes!`
|
|
||||||
and our own custom `include_dir!` implementation.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```rs
|
|
||||||
let contents: Cow<'_, str> = embed::string!("path/to/file.txt");
|
|
||||||
let bytes: Cow<'_, [u8]> = embed::bytes!("path/to/image.png");
|
|
||||||
|
|
||||||
let dir: embed::Dir = embed::dir!("path/to");
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
```
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023-present RGBCube
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
```
|
|
Loading…
Add table
Add a link
Reference in a new issue