[][src]Function detect_lang::from_extension

pub fn from_extension<S: AsRef<str>>(extension: S) -> Option<Language<'static>>

Identifies a language from a file extension. The casing of the extension does not affect the result. Returns None if the language was not identified.

See also from_path.

If the extension is guaranteed to always be lowercase, then consider using from_lowercase_extension to avoid allocation and conversion to lowercase.

Example

assert_eq!(from_extension("rs"), Some(Language("Rust", "rust")));
assert_eq!(from_extension("md"), Some(Language("Markdown", "markdown")));
assert_eq!(from_extension("cpp"), Some(Language("C++", "cpp")));
assert_eq!(from_extension("unknown"), None);

// The case is ignored
assert_eq!(from_extension("jSoN"), Some(Language("JSON", "json")));

Unsupported Language

If a language is not supported, then feel free to submit an issue on the issue tracker, or add it to languages.rs and submit a pull request.