Skip to content

Commit 861b05e

Browse files
committed
rustfmt
1 parent a12563d commit 861b05e

File tree

13 files changed

+153
-96
lines changed

13 files changed

+153
-96
lines changed

src/clojure_std.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pub (crate) mod thread;
2-
pub (crate) mod time;
3-
pub (crate) mod env;
1+
pub(crate) mod env;
2+
pub(crate) mod thread;
3+
pub(crate) mod time;

src/clojure_std/env.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::ifn::IFn;
33
use crate::value::{ToValue, Value};
44
use std::rc::Rc;
55

6-
use std::env;
76
use crate::type_tag::TypeTag;
7+
use std::env;
88

99
/// provides a function to return env variables
1010
/// similair to Clojure (System/getenv [key])
@@ -20,13 +20,11 @@ impl IFn for GetEnvFn {
2020
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
2121
if args.len() == 1 {
2222
match args.get(0).unwrap().to_value() {
23-
Value::String(key) => {
24-
match env::var(key) {
25-
Ok(val) => Value::String(val),
26-
Err(_) => Value::Nil
27-
}
28-
}
29-
_a => error_message::type_mismatch(TypeTag::String, &_a)
23+
Value::String(key) => match env::var(key) {
24+
Ok(val) => Value::String(val),
25+
Err(_) => Value::Nil,
26+
},
27+
_a => error_message::type_mismatch(TypeTag::String, &_a),
3028
}
3129
} else {
3230
return error_message::wrong_arg_count(1, args.len());

src/clojure_string/join.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::iterable::Iterable;
21
use crate::ifn::IFn;
2+
use crate::iterable::Iterable;
33
use crate::value::{ToValue, Value};
44
use std::rc::Rc;
55

@@ -22,7 +22,7 @@ impl IFn for JoinFn {
2222
if args.len() != 1 && args.len() != 2 {
2323
return error_message::wrong_varg_count(&[1, 2], args.len());
2424
}
25-
25+
2626
let separator = if args.len() == 1 {
2727
String::from("")
2828
} else {
@@ -40,13 +40,11 @@ impl IFn for JoinFn {
4040
.iter()
4141
.map(|x| x.to_string())
4242
.collect::<Vec<std::string::String>>()
43-
.join(&separator)
43+
.join(&separator),
4444
)
45-
}
46-
else {
45+
} else {
4746
Value::String(String::from(""))
4847
}
49-
5048
}
5149
}
5250

src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,33 @@ mod repl;
2121
mod rust_core;
2222
mod symbol;
2323
mod type_tag;
24+
mod user_action;
2425
mod util;
2526
mod value;
26-
mod user_action;
2727

2828
fn main() {
29-
let cli_args: user_action::Action = user_action::parse_args( std::env::args().collect() );
29+
let cli_args: user_action::Action = user_action::parse_args(std::env::args().collect());
3030

3131
// instantiate the core environment
3232
let repl = repl::Repl::default();
33-
33+
3434
match cli_args {
3535
// eval the file/script
3636
user_action::Action::RunScript(script) => {
3737
println!("{}", repl::Repl::eval_file(&repl, script.as_str()));
38-
},
38+
}
3939

4040
// eval the expression
4141
user_action::Action::Evaluate(expression) => {
42-
println!("{}", repl::Repl::eval(&repl, &repl::Repl::read_string(&expression)));
43-
},
42+
println!(
43+
"{}",
44+
repl::Repl::eval(&repl, &repl::Repl::read_string(&expression))
45+
);
46+
}
4447

4548
// Start repl
46-
user_action::Action::Nothing => { repl.run(); }
49+
user_action::Action::Nothing => {
50+
repl.run();
51+
}
4752
}
4853
}

src/reader.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub fn symbol_parser(input: &str) -> IResult<&str, Symbol> {
232232
}
233233

234234
pub fn string_parser(input: &str) -> IResult<&str, String> {
235-
// Convert escaped characters like \n to their actual counterparts -- like an actual newline
235+
// Convert escaped characters like \n to their actual counterparts -- like an actual newline
236236
named!(escaped_string_parser<&str, String>, escaped_transform!(take_till1!(|ch| { ch == '\\' || ch == '\"'}), '\\', alt!(
237237
tag!("t") => { |_| "\t" } |
238238
tag!("b") => { |_| "\x08" } |
@@ -243,18 +243,18 @@ pub fn string_parser(input: &str) -> IResult<&str, String> {
243243
tag!("\"") => { |_| "\"" } |
244244
tag!("\\") => { |_| "\\" }
245245
)));
246-
246+
247247
named!(empty_string_parser <&str, String>, map!(tag!("\"\""),|_| String::from("")));
248248

249249
named!(
250250
string_parser<&str, String>,
251251
alt!(
252-
delimited!(tag("\""),escaped_string_parser, tag("\"")) |
253-
// Base case; empty string
252+
delimited!(tag("\""),escaped_string_parser, tag("\"")) |
253+
// Base case; empty string
254254
empty_string_parser)
255255
);
256256

257-
string_parser(input)
257+
string_parser(input)
258258
}
259259

260260
// Helper function to integer_parser for same reason as
@@ -773,7 +773,6 @@ mod tests {
773773
);
774774
}
775775

776-
777776
#[test]
778777
fn try_read_string_empty() {
779778
assert_eq!(

src/repl.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io::Write;
66

77
use crate::environment::Environment;
88
use crate::reader;
9-
use crate::value::{Value,Evaluable,ToValue};
9+
use crate::value::{Evaluable, ToValue, Value};
1010
use std::rc::Rc;
1111

1212
pub struct Repl {
@@ -28,7 +28,7 @@ impl Repl {
2828
pub fn read<R: BufRead>(reader: &mut R) -> Value {
2929
reader::read(reader)
3030
}
31-
// @TODO add to reader.rs and wrap here
31+
// @TODO add to reader.rs and wrap here
3232
pub fn read_string(string: &str) -> Value {
3333
Repl::read(&mut string.as_bytes())
3434
}
@@ -100,30 +100,30 @@ impl Default for Repl {
100100
mod tests {
101101
use crate::repl::Repl;
102102
use crate::value::Value;
103-
//@TODO separate into individual tests
103+
//@TODO separate into individual tests
104104
#[test]
105105
fn read_string() {
106106
let num = Repl::read_string("1");
107107
match num {
108-
Value::I32(_) => {},
109-
_ => panic!("Reading of integer should have returned Value::I32")
108+
Value::I32(_) => {}
109+
_ => panic!("Reading of integer should have returned Value::I32"),
110110
}
111111
let list = Repl::read_string("(+ 1 2)");
112112
match list {
113-
Value::PersistentList(_) => {},
114-
_ => panic!("Reading of integer should have returned Value::PersistentList")
113+
Value::PersistentList(_) => {}
114+
_ => panic!("Reading of integer should have returned Value::PersistentList"),
115115
}
116116

117117
let vector = Repl::read_string("[1 2 a]");
118118
match vector {
119-
Value::PersistentVector(_) => {},
120-
_ => panic!("Reading of integer should have returned Value::PersistentVector")
119+
Value::PersistentVector(_) => {}
120+
_ => panic!("Reading of integer should have returned Value::PersistentVector"),
121121
}
122122

123123
let symbol = Repl::read_string("abc");
124124
match symbol {
125-
Value::Symbol(_) => {},
126-
_ => panic!("Reading of integer should have returned Value::Symbol")
125+
Value::Symbol(_) => {}
126+
_ => panic!("Reading of integer should have returned Value::Symbol"),
127127
}
128128
}
129129
}

src/rust_core.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub use self::string_print::*;
5959
pub(crate) mod read_line;
6060
pub use self::read_line::*;
6161

62-
6362
// other
6463
pub(crate) mod slurp;
6564
pub use self::slurp::*;

src/rust_core/equals.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl ToValue for EqualsFn {
1616
impl IFn for EqualsFn {
1717
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
1818
if args.is_empty() {
19-
//@TODO use proper error function
19+
//@TODO use proper error function
2020
return Value::Condition(format!(
2121
"Wrong number of arguments given to function (Given: {}, Expected: > 0)",
2222
args.len()
@@ -29,41 +29,44 @@ impl IFn for EqualsFn {
2929
if a != b {
3030
return Value::Boolean(false);
3131
}
32-
};
32+
}
3333
Value::Boolean(true)
34-
3534
}
3635
}
3736

3837
mod tests {
39-
use crate::value::{Value,ToValue};
40-
use crate::rust_core::EqualsFn;
41-
use crate::keyword::Keyword;
4238
use crate::ifn::IFn;
39+
use crate::keyword::Keyword;
40+
use crate::rust_core::EqualsFn;
41+
use crate::value::{ToValue, Value};
4342

4443
// Just checks that different Values do not count as equal, and that
4544
// at least one Value of the same kind does, and that one Value of the same
4645
// kind and different Value doesn't
4746
//
48-
// Otherwise, does not test every type
47+
// Otherwise, does not test every type
4948
#[test]
5049
fn equals_basic() {
51-
let equals = EqualsFn{};
50+
let equals = EqualsFn {};
5251
let _i32 = Value::I32(1).to_rc_value();
5352
// To test that we're not getting some sort of 'memory equality'
5453
let i32_copy = Value::I32(1).to_rc_value();
55-
assert!(equals.invoke(vec![i32_copy.clone(),_i32.clone()]).is_truthy());
56-
assert!(equals.invoke(vec![_i32.clone(),_i32.clone()]).is_truthy());
54+
assert!(equals
55+
.invoke(vec![i32_copy.clone(), _i32.clone()])
56+
.is_truthy());
57+
assert!(equals.invoke(vec![_i32.clone(), _i32.clone()]).is_truthy());
5758

5859
let i32_2 = Value::I32(5).to_rc_value();
59-
assert!(!equals.invoke(vec![_i32.clone(),i32_2.clone()]).is_truthy());
60-
60+
assert!(!equals.invoke(vec![_i32.clone(), i32_2.clone()]).is_truthy());
61+
6162
let keyword = Keyword::intern("cat").to_rc_value();
6263
let keyword2 = Keyword::intern("cat").to_rc_value();
6364
let keyword3 = Keyword::intern("dog").to_rc_value();
6465

65-
assert!(equals.invoke(vec![keyword.clone(),keyword2.clone()]).is_truthy());
66-
assert!(!equals.invoke(vec![keyword2,keyword3]).is_truthy());
67-
assert!(!equals.invoke(vec![keyword,_i32]).is_truthy());
66+
assert!(equals
67+
.invoke(vec![keyword.clone(), keyword2.clone()])
68+
.is_truthy());
69+
assert!(!equals.invoke(vec![keyword2, keyword3]).is_truthy());
70+
assert!(!equals.invoke(vec![keyword, _i32]).is_truthy());
6871
}
6972
}

src/rust_core/flush_stdout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::ifn::IFn;
2-
use crate::value::{Value, ToValue};
2+
use crate::value::{ToValue, Value};
33
use std::rc::Rc;
44

55
use std::io;
66

77
use crate::error_message;
8-
use std::io::{Write};
8+
use std::io::Write;
99

1010
/// Read a line from stdin TODO: should be aware of *in*
1111
/// (defn read-line [])
@@ -19,7 +19,7 @@ impl ToValue for FlushStdoutFn {
1919
impl IFn for FlushStdoutFn {
2020
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
2121
if args.len() != 0 {
22-
return error_message::wrong_arg_count(0, args.len())
22+
return error_message::wrong_arg_count(0, args.len());
2323
}
2424
io::stdout().flush();
2525
Value::Nil

src/rust_core/read_line.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ifn::IFn;
2-
use crate::value::{Value, ToValue};
2+
use crate::value::{ToValue, Value};
33
use std::rc::Rc;
44

55
use std::io;
@@ -19,15 +19,15 @@ impl ToValue for ReadLineFn {
1919
impl IFn for ReadLineFn {
2020
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
2121
if args.len() != 0 {
22-
return error_message::wrong_arg_count(0, args.len())
22+
return error_message::wrong_arg_count(0, args.len());
2323
}
2424
let mut input = String::new();
2525
match io::stdin().read_line(&mut input) {
2626
Ok(_) => {
2727
input.pop();
2828
Value::String(input)
29-
},
30-
Err(error) => error_message::generic_err(Box::try_from(error).unwrap())
29+
}
30+
Err(error) => error_message::generic_err(Box::try_from(error).unwrap()),
3131
}
3232
}
3333
}

0 commit comments

Comments
 (0)