Skip to content

Commit aadd5d4

Browse files
committed
Clean up iterable to use new protocol macro
1 parent faa0d43 commit aadd5d4

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

src/iterable.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,15 @@ use crate::persistent_list_map::ToPersistentListMapIter;
55
use crate::persistent_vector::PersistentVectorIter;
66
use crate::persistent_vector::ToPersistentVector;
77
use crate::persistent_vector::ToPersistentVectorIter;
8+
use crate::define_protocol;
89
use crate::protocol::Protocol;
910
use crate::value::ToValue;
1011
use crate::value::Value;
1112
use std::rc::Rc;
13+
// @TODO move to protocols::iterable
14+
15+
define_protocol!(Iterable,PersistentList,PersistentListMap,PersistentVector);
1216

13-
//
14-
// This Protocol lives inside of Clojure RS
15-
//
16-
#[derive(Debug, Clone)]
17-
pub struct Iterable {
18-
value: Rc<Value>,
19-
}
20-
impl Protocol for Iterable {
21-
fn try_as_protocol(val: &Rc<Value>) -> Option<Self> {
22-
match &**val {
23-
Value::PersistentList(_) => Some(Iterable {
24-
value: Rc::clone(val),
25-
}),
26-
Value::PersistentVector(_) => Some(Iterable {
27-
value: Rc::clone(val),
28-
}),
29-
Value::PersistentListMap(_) => Some(Iterable {
30-
value: Rc::clone(val),
31-
}),
32-
_ => None,
33-
}
34-
}
35-
fn try_unwrap(&self) -> Option<Rc<Value>> {
36-
match &*self.value {
37-
Value::PersistentList(_) => Some(Rc::clone(&self.value)),
38-
Value::PersistentVector(_) => Some(Rc::clone(&self.value)),
39-
Value::PersistentListMap(_) => Some(Rc::clone(&self.value)),
40-
_ => None,
41-
}
42-
}
43-
}
4417
pub enum IterableIter {
4518
PersistentList(PersistentListIter),
4619
PersistentVector(PersistentVectorIter),

0 commit comments

Comments
 (0)