Struct EditorConfig

Source
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)
5fn main() {
6    let editorconfig_path = "tests/test_data/.editorconfig";
7
8    // File must be provided
9    let editorconfig = EditorConfig::from_file(editorconfig_path).unwrap();
10
11    if let Some(indent_style) = editorconfig.get_property("*", "end_of_line") {
12        println!("EOL: {}", indent_style);
13    } else {
14        println!("End of line not specified.");
15    }
16}
Source

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

Examples found in repository?
examples/get_property.rs (line 11)
5fn main() {
6    let editorconfig_path = "tests/test_data/.editorconfig";
7
8    // File must be provided
9    let editorconfig = EditorConfig::from_file(editorconfig_path).unwrap();
10
11    if let Some(indent_style) = editorconfig.get_property("*", "end_of_line") {
12        println!("EOL: {}", indent_style);
13    } else {
14        println!("End of line not specified.");
15    }
16}
More examples
Hide additional examples
examples/from_str.rs (line 17)
5fn main() {
6    let editorconfig_str = r#"
7        [*]
8        indent_style = tab
9        indent_size = 4
10
11        [*.js]
12        indent_style = space
13    "#;
14
15    let editorconfig: EditorConfig = editorconfig_str.parse().unwrap();
16
17    if let Some(indent_style) = editorconfig.get_property("*.js", "indent_style") {
18        println!("Indent Style: {}", indent_style);
19    } else {
20        println!("Indent style not specified.");
21    }
22}

Trait Implementations§

Source§

impl FromStr for EditorConfig

Source§

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>,

Source§

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>,

Source§

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.