Expand description
Built-in magic rules compiled at build time.
This module contains magic rules that are compiled into the library binary
at build time from the src/builtin_rules.magic file. The rules are parsed
during the build process and converted into Rust code for efficient loading.
The BUILTIN_RULES static is lazily initialized on first access using
std::sync::LazyLock, ensuring minimal overhead when not used.
§Build-Time Generation
During cargo build, the build script (build.rs):
- Reads and parses
src/builtin_rules.magic - Converts the magic rules into Rust code
- Generates a static
LazyLock<Vec<MagicRule>>containing all rules - Writes the generated code to
$OUT_DIR/builtin_rules.rs
This module includes that generated file and provides a public API to access the compiled rules.
§Coverage
The built-in rules include high-confidence detection patterns for common file types:
- Executables: ELF, PE/DOS
- Archives: ZIP, TAR, GZIP
- Images: JPEG, PNG, GIF, BMP
- Documents: PDF
§Example
use libmagic_rs::builtin_rules::get_builtin_rules;
let rules = get_builtin_rules();
println!("Loaded {} built-in rules", rules.len());Statics§
- BUILTIN_
RULES - Built-in magic rules compiled at build time.
Functions§
- get_
builtin_ rules - Returns a copy of the built-in magic rules.