-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathset_ref.rs
36 lines (32 loc) · 866 Bytes
/
set_ref.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::marker::PhantomData;
use crate::{
StackShared,
ref_::Ref,
list_ref::ToListMappable,
MapKV,
ListRef,
};
// Implemented by things that can be mapped from a set data source
pub struct SetRef<T: Ref> {
pub(crate) shared: StackShared,
pub(crate) base: String,
_pd: PhantomData<T>,
}
impl<T: Ref> Ref for SetRef<T> {
fn new(shared: StackShared, base: String) -> Self {
SetRef {
shared: shared,
base: base,
_pd: Default::default(),
}
}
}
impl<T: Ref> SetRef<T> {
pub fn map<O: ToListMappable>(&self, inner: impl FnOnce(MapKV<T>) -> O) -> O::O {
let out = inner(MapKV::new(self.shared.clone()));
out.do_map(self.base.clone())
}
pub fn as_list(self) -> ListRef<T> {
ListRef::new(self.shared, format!("tolist({})", self.base))
}
}