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

Rename to embd

This commit is contained in:
RGBCube 2024-02-22 10:50:17 +03:00
parent 7c2eb614db
commit 53f550c9c0
No known key found for this signature in database
10 changed files with 86 additions and 91 deletions

8
.gitignore vendored
View file

@ -1,10 +1,10 @@
*
!embed/
!embed/src/
!embd/
!embd/src/
!embed-macros/
!embed-macros/src/
!embd-macros/
!embd-macros/src/
!.gitignore

27
Cargo.lock generated
View file

@ -3,14 +3,14 @@
version = 3
[[package]]
name = "embed"
name = "embd"
version = "0.1.0"
dependencies = [
"embed-macros",
"embd-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "embed-macros"
name = "embd-macros"
version = "0.1.0"
dependencies = [
"proc-macro2",
@ -19,10 +19,21 @@ dependencies = [
]
[[package]]
name = "proc-macro2"
version = "1.0.76"
name = "embd-macros"
version = "0.1.0"
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 = [
"unicode-ident",
]
@ -38,9 +49,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.48"
version = "2.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb"
dependencies = [
"proc-macro2",
"quote",

View file

@ -1,3 +1,3 @@
[workspace]
members = [ "embed", "embed-macros" ]
members = [ "embd", "embd-macros" ]
resolver = "2"

View file

@ -1,7 +1,7 @@
# embed-rs
# embd-rs
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.
It is also super efficient, and does not heap allocate when the
@ -16,24 +16,27 @@ Add this to your Cargo.toml:
```toml
[dependencies]
embed = { git = "https://github.com/RGBCube/embed-rs" }
[patch.crates-io]
proc-macro2 = { git = "https://github.com/RGBCube/proc-macro2" }
embd = "0.1"
```
Then you can use this crate as so:
Then you can use this crate like so:
```rs
let contents: Cow<'_, str> = embed::string!("path/to/file.txt");
let bytes: Cow<'_, [u8]> = embed::bytes!("path/to/image.png");
let contents: Cow<'_, str> = embd::string!("path/to/file.txt");
let bytes: Cow<'_, [u8]> = embd::bytes!("path/to/image.png");
let dir: embed::Dir = embed::dir!("path/to");
let files: Vec<embed::File> = dir.flatten();
let dir: embd::Dir = embd::dir!("path/to");
let files: Vec<embd::File> = dir.flatten();
```
I am not sure what name to publish this
crate in, lmk if you find a good one.
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

View file

@ -1,7 +1,7 @@
[package]
name = "embed-macros"
name = "embd-macros"
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"
keywords = [ "embedding", "files", "debug-optimization", "bundling" ]
categories = [ "filesystem" ]

View file

@ -1,3 +1,4 @@
#![cfg(feature = "procmacro2_semver_exempt")]
use std::{
fs,
path::Path,
@ -52,7 +53,7 @@ pub fn __dir(input: pm1::TokenStream) -> pm1::TokenStream {
fn dir_debug(path: &str) -> TokenStream {
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);
quote! {
::embed::Dir {
::embd::Dir {
__children: #children,
__path: ::std::borrow::Cow::Borrowed(#directory_str),
}
@ -98,14 +99,14 @@ fn read_dir(directory: &Path) -> TokenVec {
let children = read_dir(&path);
entries.push(quote! {
::embed::DirEntry::Dir(::embed::Dir {
::embd::DirEntry::Dir(::embd::Dir {
__children: #children,
__path: ::std::borrow::Cow::Borrowed(#path_str),
})
});
} else if filetype.is_file() {
entries.push(quote! {
::embed::DirEntry::File(::embed::File {
::embd::DirEntry::File(::embd::File {
__content: ::std::borrow::Cow::Borrowed(include_bytes!(#path_str)),
__path: ::std::borrow::Cow::Borrowed(#path_str),
})

View file

@ -1,7 +1,7 @@
[package]
name = "embed"
name = "embd"
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"
keywords = [ "embedding", "files", "debug-optimization", "bundling" ]
categories = [ "filesystem" ]
@ -10,4 +10,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
embed-macros = { path = "../embed-macros" }
embd-macros = "0.1"

View file

@ -1,19 +1,41 @@
# embed-rs
# embd-rs
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.
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!`
and our own custom `include_dir!` implementation.
and our own custom `include_dir!`-like implementation.
## Usage
```rs
let contents: Cow<'_, str> = embed::string!("path/to/file.txt");
let bytes: Cow<'_, [u8]> = embed::bytes!("path/to/image.png");
Add this to your Cargo.toml:
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

View file

@ -1,3 +1,4 @@
#![cfg(feature = "procmacro2_semver_exempt")]
use std::{
borrow::Cow,
fs,
@ -21,7 +22,7 @@ pub fn __string_runtime(neighbor: &str, path: &str) -> String {
///
/// ```
/// fn main() {
/// let content: Cow<'static, str> = embed::string!("main.rs");
/// let content: Cow<'static, str> = embd::string!("main.rs");
/// }
/// ```
#[macro_export]
@ -29,7 +30,7 @@ macro_rules! string {
($path:literal) => {{
#[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))]
{
@ -56,7 +57,7 @@ pub fn __bytes_runtime(neighbor: &str, path: &str) -> Vec<u8> {
/// ```
/// fn main() {
/// // `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]
@ -64,7 +65,7 @@ macro_rules! bytes {
($path:literal) => {{
#[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))]
{
@ -218,7 +219,7 @@ pub fn __dir_runtime(neighbor: &str, path: &str) -> Dir {
///
/// ```
/// 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;

View file

@ -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.
```