languages

Crates.iolanguages
lib.rslanguages
version0.0.2
created_at2025-07-25 05:58:19.176723+00
updated_at2025-07-25 06:58:08.074289+00
descriptionGitHub's language data, compiled into a tiny, fast Rust library
homepage
repositoryhttps://github.com/cortesi/languages
max_upload_size
id1767233
size174,930
Aldo Cortesi (cortesi)

documentation

README

Discord Crates.io docs.rs

languages

GitHub's language data, compiled into a tiny, fast Rust library. 🦀

This crate provides an efficient way to look up language information from GitHub's Linguist languages.yml file. The data is parsed at compile-time and baked directly into your binary, making lookups instantaneous with zero runtime overhead.


Features

  • Fast: All data is stored in static HashMaps for instant, case-insensitive lookups.
  • Simple API: Get language info by name, alias, extension, or CodeMirror mode.
  • Self-Contained: No need to read files or parse YAML at runtime.

Quickstart

  1. Add languages to your Cargo.toml:

    [dependencies]
    languages = "0.1.0" # Replace with the latest version
    
  2. Use the lookup functions:

    let lang = languages::from_extension("rs").unwrap();
    assert_eq!(lang.name, "Rust");
    assert_eq!(lang.language_type, "programming");
    assert_eq!(lang.color, Some("#dea584"));
    
    // Look up by name (case-insensitive)
    let python = languages::from_name("Python").unwrap();
    assert!(python.extensions.unwrap().contains(&".py"));
    
    // Look up by alias
    let cpp = languages::from_name("cpp").unwrap();
    assert_eq!(cpp.name, "C++");
    

How It Works

This crate uses a build.rs script that parses languages.yml and generates the necessary Rust code. To update the language data to the latest version from GitHub, simply run the download_languages.sh script and recompile your project.

Related Projects

This library was written to be used in the snips tool, which is also used to maintain the code examples in this README.

License and Acknowledgements

The code for the languages crate is licensed under the MIT License.

The language data is sourced from the GitHub Linguist project, which is distributed under the MIT license and is copyright of GitHub, Inc.

Commit count: 0

cargo fmt