pub fn from_path<P: AsRef<Path>>(path: P) -> Option<Language<'static>>
Expand description
Identifies a language from a path extension.
The casing of the extension does not affect the result.
Returns None
if the language was not identified.
Note that from_path
does not check if the path exists,
nor does it attempt to load the file.
§Example
assert_eq!(from_path("foo.rs"), Some(Language("Rust", "rust")));
assert_eq!(from_path("foo.md"), Some(Language("Markdown", "markdown")));
assert_eq!(from_path("foo.cpp"), Some(Language("C++", "cpp")));
assert_eq!(from_path("foo.unknown"), None);
// The case is ignored
assert_eq!(from_path("foo.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.