#[magic_embed]Expand description
Procedural macro to embed a compiled pure_magic::MagicDb
This attribute macro compiles magic rule files at program compile time and embeds them in the binary. The database will not be automatically rebuilt when rule files change (c.f. see Note section below).
§Attributes
include- Array of paths to include in the database (required)exclude- Array of paths to exclude from the database (optional)
§Examples
use magic_embed::magic_embed;
use pure_magic::MagicDb;
#[magic_embed(include=["../../magic-db/src/magdir"], exclude=["../../magic-db/src/magdir/der"])]
struct EmbeddedMagicDb;
let db: MagicDb = EmbeddedMagicDb::open().unwrap();§Errors
This macro will emit a compile-time error if:
- The
includeattribute is missing - Specified paths don’t exist
- Database compilation fails
- File I/O operations fail
§Note
If you want Cargo to track changes to your rule files (e.g., magdir/),
you must create a build script in your project. The proc-macro cannot
track these files directly because it embeds only the compiled database,
not the rule files themselves. Add a build.rs file like this:
ⓘ
// build.rs
fn main() {
println!("cargo::rerun-if-changed=magdir/");
}Replace magdir/ with the path to your rule files.