Crate editorconfig_core

Source
Expand description

An EditorConfig Core passing all the editorconfig-core-test tests.

§Examples

use editorconfig_core::properties;

// Let's define the property we want to extract.

enum EndOfLine { Cr, Crlf, Lf }

impl EndOfLine {
    const KEY: &str = "end_of_line";

    fn from_str<S: AsRef<str>>(s: S) -> Option<Self> {
        match s.as_ref() {
            "cr" => Some(Self::Cr),
            "crlf" => Some(Self::Crlf),
            "lf" => Some(Self::Lf),
            _ => None,
        }
    }
}

// Now, fetch the properties for our file.

// Must be a full, normalized, valid unicode path.
let path = "/home/myself/README.md";

let mut properties = properties(path).unwrap();

// Discard properties that was unset.
properties.retain(|_key, value| !value.eq_ignore_ascii_case("unset"));

// Extract the property.
let eof = properties.get(EndOfLine::KEY).and_then(EndOfLine::from_str);

§Notes

  • All the keys are already lowercased via str::to_lowercase.
  • The values are kept in their original form, except for the values of the “Supported” properties.

Structs§

Options
Version

Enums§

Error

Constants§

MAX_VERSION
Max. supported EditorConfig version.

Functions§

properties
Retreives the properties for the file at path.
properties_with_options

Type Aliases§

Properties
All the keys are lowercased, values are kept in their original form, except for the values of “Supported” properties.