-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprim_ref.rs
82 lines (68 loc) · 1.93 KB
/
prim_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std::marker::PhantomData;
use crate::{
StackShared,
PrimType,
Expr,
manual_expr_impls,
prim_field::PrimField,
list_ref::{
MapListRef,
MapListRefToRec,
ToListMappable,
RecToListMappable,
},
rec_ref::{
MapRecRef,
MapRecRefToList,
ListToRecMappable,
ToObjMappable,
},
Ref,
};
use std::fmt::Display;
/// This represents a value that can be passed to functions, put in fields, etc.
pub struct PrimExpr<T: PrimType>(pub(crate) StackShared, pub(crate) String, pub(crate) PhantomData<T>);
impl<T: PrimType> Expr<T> for PrimExpr<T> {
fn expr_raw(&self) -> (&StackShared, String) {
(&self.0, self.1.clone())
}
fn expr_sentinel(&self) -> String {
self.0.add_sentinel(&self.1)
}
}
impl<T: PrimType> PrimExpr<T> {
pub fn raw(&self) -> String {
self.1.clone()
}
}
manual_expr_impls!(PrimExpr);
// References
impl<T: PrimType> Ref for PrimExpr<T> {
fn new(shared: StackShared, base: String) -> PrimExpr<T> {
PrimExpr(shared, base, Default::default())
}
}
impl<T: PrimType> ToListMappable for PrimExpr<T> {
type O = MapListRef<PrimField<T>>;
fn do_map(self, base: String) -> Self::O {
MapListRef::new(self.0, base, self.1)
}
}
impl<T: PrimType> ListToRecMappable for PrimExpr<T> {
type O = MapListRefToRec<PrimField<T>>;
fn do_map_rec(self, base: String, k: PrimExpr<String>) -> Self::O {
MapListRefToRec::new(self.0, base, k.1, self.1)
}
}
impl<T: PrimType> RecToListMappable for PrimExpr<T> {
type O = MapRecRefToList<PrimField<T>>;
fn do_map(self, base: String) -> Self::O {
MapRecRefToList::new(self.0, base, self.1)
}
}
impl<T: PrimType> ToObjMappable for PrimExpr<T> {
type O = MapRecRef<PrimField<T>>;
fn do_map_rec(self, base: String, k: PrimExpr<String>) -> Self::O {
MapRecRef::new(self.0, base, k.1, self.1)
}
}