pub struct EditorConfig {
    pub config: HashMap<String, HashMap<String, String>>,
}

Fields§

§config: HashMap<String, HashMap<String, String>>

Implementations§

source§

impl EditorConfig

source

pub fn from_file(file_path: &str) -> Result<Self, String>

Examples found in repository?
examples/get_property.rs (line 9)
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    let editorconfig_path = "tests/test_data/.editorconfig";

    // File must be provided
    let editorconfig = EditorConfig::from_file(editorconfig_path).unwrap();

    if let Some(indent_style) = editorconfig.get_property("*", "end_of_line") {
        println!("EOL: {}", indent_style);
    } else {
        println!("End of line not specified.");
    }
}
source

pub fn get_property(&self, section: &str, property: &str) -> Option<&String>

Examples found in repository?
examples/get_property.rs (line 11)
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    let editorconfig_path = "tests/test_data/.editorconfig";

    // File must be provided
    let editorconfig = EditorConfig::from_file(editorconfig_path).unwrap();

    if let Some(indent_style) = editorconfig.get_property("*", "end_of_line") {
        println!("EOL: {}", indent_style);
    } else {
        println!("End of line not specified.");
    }
}
More examples
Hide additional examples
examples/from_str.rs (line 17)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let editorconfig_str = r#"
        [*]
        indent_style = tab
        indent_size = 4

        [*.js]
        indent_style = space
    "#;

    let editorconfig: EditorConfig = editorconfig_str.parse().unwrap();

    if let Some(indent_style) = editorconfig.get_property("*.js", "indent_style") {
        println!("Indent Style: {}", indent_style);
    } else {
        println!("Indent style not specified.");
    }
}

Trait Implementations§

source§

impl FromStr for EditorConfig

§

type Err = String

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.