| Crates.io | src_embed |
| lib.rs | src_embed |
| version | 0.1.0 |
| created_at | 2026-01-08 20:56:29.95097+00 |
| updated_at | 2026-01-08 20:56:29.95097+00 |
| description | A procedural macro to embed source files into Rust binaries. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 2031054 |
| size | 11,102 |
src-embed is a tiny procedural attribute macro that embeds the original
Rust source of an annotated item into the compiled crate as a pub const
string. The generated constant is marked #[doc(hidden)] and the original
item is re-emitted unchanged so the macro preserves semantics while making the
textual source available at compile time or runtime.
Sometimes it's useful to keep the literal source of a type, function, trait,
or impl block available in the binary for tests, examples, debug output, or
documentation tooling. src-embed provides a simple, dependency-light way to
make that source accessible.
struct, enum, fn, trait, and impl items.pub const __<NAME>_SOURCE__: &str containing the source.Note: the embedded source includes the original attributes and doc
comments associated with the annotated item. This ensures /// doc
comments (and other outer attributes) appear in the generated string.
Add the crate as a dependency (path or registry as appropriate) and enable the
proc-macro feature in your Cargo.toml if using a local crate.
[dependencies]
src-embed = { path = ".." }
Then annotate an item:
use src_embed::src_embed;
#[src_embed]
pub struct Foo { pub x: u32 }
// You can now refer to `__FOO_SOURCE__` (it is `pub`, but marked
// `#[doc(hidden)]`).
Given:
#[src_embed]
pub fn example() -> &'static str { "hello" }
The macro will emit something like:
#[doc(hidden)]
pub const __EXAMPLE_SOURCE__: &str = "pub fn example() -> &'static str { \"hello\" }";
pub fn example() -> &'static str { "hello" }
__ and _SOURCE__. For certain items (like impls) the
macro derives a representative name; when it cannot, it falls back to
ITEM or UNKNOWN.This repository is provided under the terms of the included LICENSE file.