Skip to content

Commit 6a5ef17

Browse files
committed
Add config.rs which I forgot for the last commit
Closes #73
1 parent 1a09a6d commit 6a5ef17

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/config.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}
23+
24+
impl Config {
25+
fn from_toml(toml: &str) -> Config {
26+
println!("About to parse: {}", toml);
27+
let parsed = toml.parse().unwrap();
28+
toml::decode(parsed).unwrap()
29+
}
30+
}
31+
32+
pub fn set_config(toml: &str) {
33+
unsafe {
34+
::CONFIG = Some(Config::from_toml(toml));
35+
}
36+
}
37+
38+
macro_rules! config {
39+
($name: ident) => {
40+
unsafe { ::CONFIG.as_ref().unwrap().$name }
41+
};
42+
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ impl<'a> CompilerCalls<'a> for RustFmtCalls {
267267
changes.append_newlines();
268268
fmt_lines(&mut changes);
269269

270-
// FIXME(#5) Should be user specified whether to show or replace.
271270
let result = changes.write_all_files(write_mode);
272271

273272
match result {

0 commit comments

Comments
 (0)