Skip to content

Commit b506c89

Browse files
committed
rustfmt
1 parent 47225d4 commit b506c89

23 files changed

+716
-661
lines changed

src/environment.rs

Lines changed: 232 additions & 241 deletions
Large diffs are not rendered by default.

src/iterable.rs

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
use crate::protocol::Protocol;
2-
use crate::value::Value;
3-
use crate::value::ToValue;
4-
use crate::persistent_list_map::PersistentListMapIter;
5-
use crate::persistent_vector::PersistentVectorIter;
61
use crate::persistent_list::PersistentListIter;
7-
use crate::persistent_list_map::ToPersistentListMapIter;
8-
use crate::persistent_vector::ToPersistentVectorIter;
92
use crate::persistent_list::ToPersistentListIter;
3+
use crate::persistent_list_map::PersistentListMapIter;
4+
use crate::persistent_list_map::ToPersistentListMapIter;
5+
use crate::persistent_vector::PersistentVectorIter;
106
use crate::persistent_vector::ToPersistentVector;
11-
use std::rc::Rc;
7+
use crate::persistent_vector::ToPersistentVectorIter;
8+
use crate::protocol::Protocol;
9+
use crate::value::ToValue;
10+
use crate::value::Value;
1211
use std::iter::FromIterator;
12+
use std::rc::Rc;
1313

1414
//
1515
// This Protocol lives inside of Clojure RS
1616
//
17-
#[derive(Debug, Clone)]
17+
#[derive(Debug, Clone)]
1818
pub struct Iterable {
19-
value: Rc<Value>
19+
value: Rc<Value>,
2020
}
2121
impl Protocol for Iterable {
2222
fn try_as_protocol(val: &Rc<Value>) -> Option<Self> {
2323
match &**val {
24-
Value::PersistentList(_) =>
25-
Some(Iterable { value: Rc::clone(val)}),
26-
Value::PersistentVector(_) =>
27-
Some(Iterable { value: Rc::clone(val)}),
28-
Value::PersistentListMap(_) =>
29-
Some(Iterable { value: Rc::clone(val)}),
30-
_ =>
31-
None
24+
Value::PersistentList(_) => Some(Iterable {
25+
value: Rc::clone(val),
26+
}),
27+
Value::PersistentVector(_) => Some(Iterable {
28+
value: Rc::clone(val),
29+
}),
30+
Value::PersistentListMap(_) => Some(Iterable {
31+
value: Rc::clone(val),
32+
}),
33+
_ => None,
3234
}
3335
}
3436
fn try_unwrap(&self) -> Option<Rc<Value>> {
3537
match &*self.value {
3638
Value::PersistentList(_) => Some(Rc::clone(&self.value)),
3739
Value::PersistentVector(_) => Some(Rc::clone(&self.value)),
3840
Value::PersistentListMap(_) => Some(Rc::clone(&self.value)),
39-
_ => None
41+
_ => None,
4042
}
41-
}
43+
}
4244
}
4345
pub enum IterableIter {
4446
PersistentList(PersistentListIter),
@@ -55,24 +57,32 @@ impl Iterator for IterableIter {
5557
let maybe_map_entry = plist_map_iter.next();
5658
if let Some(map_entry) = maybe_map_entry {
5759
// In Clojure: [key val]
58-
return Some(vec![map_entry.key.clone(), map_entry.val.clone()].into_vector().to_rc_value());
60+
return Some(
61+
vec![map_entry.key.clone(), map_entry.val.clone()]
62+
.into_vector()
63+
.to_rc_value(),
64+
);
5965
}
60-
None
66+
None
6167
}
6268
}
6369
}
6470
}
6571
impl Iterable {
66-
pub fn iter(&self) -> IterableIter
67-
{
68-
match &*self.value {
69-
Value::PersistentList(plist) => IterableIter::PersistentList(Rc::new(plist.clone()).iter()),
70-
Value::PersistentVector(pvector) => IterableIter::PersistentVector(Rc::new(pvector.clone()).iter()),
71-
Value::PersistentListMap(pmap) => IterableIter::PersistentListMap(Rc::new(pmap.clone()).iter()),
72+
pub fn iter(&self) -> IterableIter {
73+
match &*self.value {
74+
Value::PersistentList(plist) => {
75+
IterableIter::PersistentList(Rc::new(plist.clone()).iter())
76+
}
77+
Value::PersistentVector(pvector) => {
78+
IterableIter::PersistentVector(Rc::new(pvector.clone()).iter())
79+
}
80+
Value::PersistentListMap(pmap) => {
81+
IterableIter::PersistentListMap(Rc::new(pmap.clone()).iter())
82+
}
7283
// We are ok panicking in this case because an invariant on the type is the assumption
73-
// that we only have an Iterable if we were able to convert
74-
_ => panic!("Called Iterable iter on non-iterable")
84+
// that we only have an Iterable if we were able to convert
85+
_ => panic!("Called Iterable iter on non-iterable"),
7586
}
76-
7787
}
7888
}

src/keyword.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,24 @@ pub struct Keyword {
1010
impl Keyword {
1111
pub fn intern(name: &str) -> Keyword {
1212
Keyword {
13-
sym: Symbol::intern(name)
13+
sym: Symbol::intern(name),
1414
}
1515
}
1616
// Note; normally 'with_x' would imply x is the second argument
1717
// here, but we are keeping the semantics of interning that
1818
// Clojure proper has
1919
pub fn intern_with_ns(ns: &str, name: &str) -> Keyword {
2020
Keyword {
21-
sym: Symbol::intern_with_ns(name,ns)
21+
sym: Symbol::intern_with_ns(name, ns),
2222
}
2323
}
2424
}
2525
impl fmt::Display for Keyword {
2626
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27-
if self.sym.ns != "" {
28-
write!(f, ":{}/{}", self.sym.ns,self.sym.name)
29-
}
30-
else {
31-
write!(f, ":{}", self.sym.name)
32-
}
33-
27+
if self.sym.ns != "" {
28+
write!(f, ":{}/{}", self.sym.ns, self.sym.name)
29+
} else {
30+
write!(f, ":{}", self.sym.name)
31+
}
3432
}
3533
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ mod clojure_std;
66
mod environment;
77
mod error_message;
88
mod ifn;
9+
mod iterable;
910
mod keyword;
1011
mod lambda;
1112
mod maps;
1213
mod namespace;
1314
mod persistent_list;
1415
mod persistent_list_map;
1516
mod persistent_vector;
17+
mod protocol;
1618
mod reader;
1719
mod repl;
1820
mod rust_core;
1921
mod symbol;
2022
mod type_tag;
2123
mod util;
2224
mod value;
23-
mod protocol;
24-
mod iterable;
2525

2626
fn main() {
2727
//

0 commit comments

Comments
 (0)