Skip to content

Commit 0e0f303

Browse files
committed
Add IPersistentList protocol
1 parent 65d3578 commit 0e0f303

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/protocols/ipersistent_list.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::value::{Value,ToValue};
2+
use std::rc::Rc;
3+
use crate::persistent_list_map;
4+
use crate::protocol::ProtocolCastable;
5+
6+
define_protocol!(IPersistentMap,PersistentListMap);
7+
8+
impl persistent_list_map::IPersistentMap for IPersistentMap {
9+
fn get(&self, key: &Rc<Value>) -> Rc<Value> {
10+
match &*self.value {
11+
Value::PersistentListMap(plist_map) => {
12+
plist_map.get(key)
13+
},
14+
_ => panic!("Called Iterable iter on non-iterable"),
15+
}
16+
}
17+
fn assoc(&self, key: Rc<Value>, value: Rc<Value>) -> IPersistentMap {
18+
match &*self.value {
19+
Value::PersistentListMap(plist_map) => {
20+
plist_map.assoc(key,value).to_rc_value().as_protocol::<IPersistentMap>()
21+
},
22+
_ => panic!("Called Iterable iter on non-iterable"),
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)