Trait SupportedLanguage

Source
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§

Source

fn name(&self) -> Cow<'_, str>

Get the name for this language.

Passing the output of this function to for_name must always result in an Ok value.

Source

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.

Source

fn for_file_type(file_type: FileType, set: &'set S) -> Option<Self>

Find a language based on the given FileType.

Implementations should return the language that supports the given file type, if there is any.

Provided Methods§

Source

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.

Implementors§

Source§

impl<'set, L, R, S, T> SupportedLanguage<'set, Union<S, T>> for EitherLang<L, R>
where L: SupportedLanguage<'set, S>, R: SupportedLanguage<'set, T>,