pub struct LanguageRegistry { /* private fields */ }Expand description
Which languages are available, and which files belong to them.
Implementations§
Source§impl LanguageRegistry
impl LanguageRegistry
Sourcepub fn register(
&mut self,
language: Arc<dyn Language>,
) -> Result<(), RegistryError>
pub fn register( &mut self, language: Arc<dyn Language>, ) -> Result<(), RegistryError>
Add a language.
§Errors
Fails when the identifier or any extension is already claimed, or when an extension
is malformed. Rejecting rather than overwriting is deliberate: a registry that
silently let the last registration win would make which language parses a .ts
file depend on registration order, and that order is not part of any contract.
A failed registration changes nothing — validation of every extension completes before any is claimed.
Sourcepub fn by_id(&self, id: &str) -> Option<&Arc<dyn Language>>
pub fn by_id(&self, id: &str) -> Option<&Arc<dyn Language>>
Look up a language by its identifier.
Sourcepub fn for_path(&self, path: impl AsRef<Path>) -> Option<&Arc<dyn Language>>
pub fn for_path(&self, path: impl AsRef<Path>) -> Option<&Arc<dyn Language>>
Which language, if any, parses this path.
The extension is lowercased before lookup, so a file named Button.TSX is still
TSX. Without this, whether a file gets checked would depend on how it was typed.
Sourcepub fn languages(&self) -> impl Iterator<Item = &Arc<dyn Language>>
pub fn languages(&self) -> impl Iterator<Item = &Arc<dyn Language>>
Every registered language, ordered by identifier.
Sourcepub fn extensions(&self) -> impl Iterator<Item = &'static str> + '_
pub fn extensions(&self) -> impl Iterator<Item = &'static str> + '_
Every extension any language claims, ordered.
Trait Implementations§
Source§impl Clone for LanguageRegistry
impl Clone for LanguageRegistry
Source§fn clone(&self) -> LanguageRegistry
fn clone(&self) -> LanguageRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LanguageRegistry
Hand-written because Arc<dyn Language> is not Debug — trait objects would have to
require it, which is a demand on every implementor for the sake of one impl here. The
keys are the useful part anyway: what is registered, and what it claims.
impl Debug for LanguageRegistry
Hand-written because Arc<dyn Language> is not Debug — trait objects would have to
require it, which is a demand on every implementor for the sake of one impl here. The
keys are the useful part anyway: what is registered, and what it claims.