]> git.lizzy.rs Git - rust.git/blob - src/config.rs
Merge pull request #94 from marcusklaas/fixes
[rust.git] / src / config.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 extern crate toml;
12
13 #[derive(RustcDecodable)]
14 pub struct Config {
15     pub max_width: usize,
16     pub ideal_width: usize,
17     pub leeway: usize,
18     pub tab_spaces: usize,
19     pub newline_style: ::NewlineStyle,
20     pub fn_brace_style: ::BraceStyle,
21     pub fn_return_indent: ::ReturnIndent,
22     pub fn_args_paren_newline: bool,
23     pub struct_trailing_comma: bool,
24     pub struct_lit_trailing_comma: ::lists::SeparatorTactic,
25     pub enum_trailing_comma: bool,
26 }
27
28 impl Config {
29     fn from_toml(toml: &str) -> Config {
30         let parsed = toml.parse().unwrap();
31         toml::decode(parsed).unwrap()
32     }
33 }
34
35 pub fn set_config(toml: &str) {
36     unsafe {
37         ::CONFIG = Some(Config::from_toml(toml));
38     }
39 }
40
41 macro_rules! config {
42     ($name: ident) => {
43         unsafe { ::CONFIG.as_ref().unwrap().$name }
44     };
45 }