1+ use std:: rc:: Rc ;
2+
13use crate :: {
2- hir:: { Event , Item , Type } ,
4+ hir:: { Event , Item , Table , Type } ,
35 mir:: {
46 Expr ,
57 builder:: { Builder , InitVar } ,
68 serdes:: { Des , Ser , Serdes } ,
79 } ,
8- shared:: { ApiCheck , NetworkSide } ,
10+ shared:: { ApiCheck , NetworkSide , Options } ,
911} ;
1012
1113mod iter;
@@ -19,33 +21,37 @@ pub struct Client {
1921 pub des : Des ,
2022}
2123
22- impl Client {
23- pub fn new ( apicheck : ApiCheck ) -> Self {
24+ impl Default for Client {
25+ fn default ( ) -> Self {
2426 let location = "result" . to_string ( ) ;
27+
2528 let ser = Ser {
26- apicheck ,
29+ options : Rc :: new ( Options :: default ( ) ) ,
2730 native : false ,
2831 } ;
32+
2933 let des = Des {
30- apicheck ,
34+ options : Rc :: new ( Options :: default ( ) ) ,
3135 native : false ,
3236 check : false ,
3337 } ;
3438
3539 Client { location, ser, des }
3640 }
41+ }
3742
38- pub fn item ( & self , b : & mut Builder , item : & Item ) {
43+ impl Client {
44+ fn item ( & self , b : & mut Builder , item : & Item ) {
3945 match item {
4046 Item :: Table ( table) => self . table ( b, table) ,
4147 Item :: Event ( event) => self . event ( b, event) ,
4248 }
4349 }
4450
45- fn table ( & self , b : & mut Builder , table : & [ ( String , Item ) ] ) {
46- for ( name, item) in table {
51+ pub fn table ( & self , b : & mut Builder , table : & Table ) {
52+ for ( name, item) in table. items . iter ( ) {
4753 self . export ( b, name, Expr :: Table ( vec ! [ ] ) ) ;
48- self . location ( name) . item ( b, item) ;
54+ self . child ( & table . options , name) . item ( b, item) ;
4955 }
5056 }
5157
@@ -56,12 +62,18 @@ impl Client {
5662 }
5763 }
5864
59- fn location ( & self , name : & str ) -> Self {
65+ fn child ( & self , options : & Rc < Options > , name : & str ) -> Self {
66+ let mut ser = self . ser . clone ( ) ;
67+ ser. options = Rc :: clone ( options) ;
68+
69+ let mut des = self . des . clone ( ) ;
70+ des. options = Rc :: clone ( options) ;
71+
6072 Client {
6173 location : self . location . clone ( ) + "." + name,
6274
63- ser : self . ser . clone ( ) ,
64- des : self . des . clone ( ) ,
75+ ser,
76+ des,
6577 }
6678 }
6779
0 commit comments