pub struct LanguageDetector;Expand description
Language detection utilities
Provides methods for detecting programming languages from file paths, file content, or both.
Implementations§
Source§impl LanguageDetector
impl LanguageDetector
Sourcepub fn from_extension(path: &Path) -> Language
pub fn from_extension(path: &Path) -> Language
Sourcepub fn from_content(content: &str) -> Language
pub fn from_content(content: &str) -> Language
Detect language from file content (shebang or imports)
§Arguments
content- The file content to analyze
§Returns
The detected language based on content patterns, or Language::Unknown
§Example
ⓘ
let lang = LanguageDetector::from_content("#!/usr/bin/env python\nprint('hello')");
assert_eq!(lang, Language::Python);Sourcepub fn detect(path: &Path, content: &str) -> Language
pub fn detect(path: &Path, content: &str) -> Language
Detect language from both extension and content
§Arguments
path- Path to the filecontent- The file content to analyze
§Returns
The detected language, preferring extension detection over content detection
§Example
ⓘ
let lang = LanguageDetector::detect(
Path::new("main.rs"),
"fn main() {}"
);
assert_eq!(lang, Language::Rust);Auto Trait Implementations§
impl Freeze for LanguageDetector
impl RefUnwindSafe for LanguageDetector
impl Send for LanguageDetector
impl Sync for LanguageDetector
impl Unpin for LanguageDetector
impl UnwindSafe for LanguageDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more