9 releases
Uses new Rust 2024
| 0.1.9 | Mar 1, 2026 |
|---|---|
| 0.1.8 | Mar 1, 2026 |
| 0.1.7 | Feb 9, 2026 |
| 0.1.6 | Dec 16, 2025 |
| 0.1.1 | Oct 31, 2025 |
#484 in Parser implementations
1,905 downloads per month
Used in 4 crates
86KB
572 lines
Linguist
A Rust library for programming language detection, inspired by GitHub Linguist. Detects programming languages by file extension, filename, and content-based heuristics.
Features
- Zero configuration and setup required, just add the crate and call the detection functions
- Detect languages by exact filename match (e.g.,
Makefile,Dockerfile) - Detect languages by file extension (e.g.,
.rs,.py,.js) - Disambiguate between multiple languages using content heuristics
- Identify vendored/third-party files
Usage
Detect by Extension
use linguist::detect_language_by_extension;
let languages = detect_language_by_extension("script.py")?;
assert_eq!(languages[0].name, "Python");
Detect by Filename
use linguist::detect_language_by_filename;
let languages = detect_language_by_filename("Makefile")?;
assert_eq!(languages[0].name, "Makefile");
Disambiguate by Content
use linguist::disambiguate;
let content = "#include <iostream>\nint main() {}";
let result = disambiguate("test.h", content)?;
if let Some(languages) = result {
assert_eq!(languages[0].name, "C++");
}
Check if Vendored
use linguist::is_vendored;
assert!(is_vendored("node_modules/react/index.js")?);
assert!(!is_vendored("src/main.rs")?);
Acknowledgments
Special thanks to @vcfxb for graciously donating the crates.io name "linguist" to this project!
This project is inspired by and uses language definitions from GitHub Linguist, maintained by GitHub and its contributors. The language definitions (definitions/languages.yml, definitions/heuristics.yml, definitions/vendor.yml) are derived from this project.
Dependencies
~5–7.5MB
~139K SLoC