pub trait SupportedLanguage<'set, S>: Sized {
// Required methods
fn name(&self) -> Cow<'_, str>;
fn for_name(name: impl AsRef<str>, set: &'set S) -> Result<Self, Error>;
fn for_file_type(file_type: FileType, set: &'set S) -> Option<Self>;
// Provided method
fn for_injection(name: impl AsRef<str>, set: &'set S) -> Option<Self> { ... }
}
Expand description
A language included in a LanguageSet
.
Instances can be obtained with for_name
,
for_file_type
, and
for_injection
.
Required Methods§
Sourcefn for_name(name: impl AsRef<str>, set: &'set S) -> Result<Self, Error>
fn for_name(name: impl AsRef<str>, set: &'set S) -> Result<Self, Error>
Get the language with the given name.
If no language for that name exists, implementations should return an
UnsupportedLanguage
error.
syntastica
itself does not provide a list of valid language names, but the
official parser collections
do. However, every string that may be returned by name
must
result in an Ok
value.
Provided Methods§
Sourcefn for_injection(name: impl AsRef<str>, set: &'set S) -> Option<Self>
fn for_injection(name: impl AsRef<str>, set: &'set S) -> Option<Self>
Find a language for an injection.
The passed name
could be any string that somehow identifies a language. This very much
depends on the source of the injection. For example, in fenced code blocks in markdown, the
text after the opening ```
is passed to this function.
Note that this function does not get called, if for_name
was able to return a language for name
.
The default implementation tries to detect a FileType
using name
as both a filename
and a file extension, and passes that to
for_file_type
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.