pub struct LanguageMap { /* private fields */ }Expand description
Maps file extensions and extensionless file names to language ids.
§Examples
use std::path::Path;
use mcpls_core::config::{FileName, LanguageId, LanguageMap, PatternTarget};
let mut map = LanguageMap::default();
map.insert(
PatternTarget::Name(FileName::from_static("Makefile")),
LanguageId::new("make").unwrap(),
);
assert_eq!(map.detect(Path::new("Makefile")), "make");
assert_eq!(map.detect(Path::new("main.rs")), LanguageId::PLAINTEXT);Implementations§
Source§impl LanguageMap
impl LanguageMap
Sourcepub fn insert(&mut self, target: PatternTarget, language: LanguageId)
pub fn insert(&mut self, target: PatternTarget, language: LanguageId)
Maps target to language, replacing an earlier mapping of the same
extension or name.
Sourcepub fn detect(&self, path: &Path) -> LanguageId
pub fn detect(&self, path: &Path) -> LanguageId
The language of path, or LanguageId::PLAINTEXT when its extension
or name is not mapped.
Sourcepub fn languages(&self) -> impl Iterator<Item = &LanguageId>
pub fn languages(&self) -> impl Iterator<Item = &LanguageId>
Every language some extension or name maps to, with repeats when several keys map to one language.
Trait Implementations§
Source§impl Clone for LanguageMap
impl Clone for LanguageMap
Source§impl Debug for LanguageMap
impl Debug for LanguageMap
Source§impl Default for LanguageMap
impl Default for LanguageMap
impl Eq for LanguageMap
Source§impl From<HashMap<FileExtension, LanguageId>> for LanguageMap
impl From<HashMap<FileExtension, LanguageId>> for LanguageMap
Source§fn from(by_extension: HashMap<FileExtension, LanguageId>) -> Self
fn from(by_extension: HashMap<FileExtension, LanguageId>) -> Self
Converts to this type from the input type.
Source§impl PartialEq for LanguageMap
impl PartialEq for LanguageMap
impl StructuralPartialEq for LanguageMap
Auto Trait Implementations§
impl Freeze for LanguageMap
impl RefUnwindSafe for LanguageMap
impl Send for LanguageMap
impl Sync for LanguageMap
impl Unpin for LanguageMap
impl UnsafeUnpin for LanguageMap
impl UnwindSafe for LanguageMap
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.