pub fn get_builtin_rules() -> Vec<MagicRule>Expand description
Returns a copy of the built-in magic rules.
This function provides access to the magic rules compiled at build time from
src/builtin_rules.magic. The rules are stored in a LazyLock static, so
initialization only happens on the first call.
§Rules Included
The built-in rules include high-confidence file type detection for:
- Executable formats: ELF (32/64-bit, LSB/MSB), PE/DOS executables
- Archive formats: ZIP, TAR (POSIX), GZIP
- Image formats: JPEG/JFIF, PNG, GIF (87a/89a), BMP
- Document formats: PDF
§Performance
The rules are lazily initialized using LazyLock, meaning:
- First call performs one-time initialization
- Subsequent calls are very fast (just cloning the Vec)
- Safe to call from multiple threads (initialization is synchronized)
§Returns
A cloned Vec<MagicRule> containing all built-in magic rules. Each caller
gets an independent copy that can be modified without affecting other callers.
§Examples
use libmagic_rs::builtin_rules::get_builtin_rules;
let rules = get_builtin_rules();
println!("Built-in rules count: {}", rules.len());
// Rules can be used directly with the evaluator
// or combined with custom rules§See Also
MagicDatabase::with_builtin_rules()- Recommended way to use built-in rulesMagicDatabase::with_builtin_rules_and_config()- With custom configuration