1
1
#![ allow( unused_variables) ]
2
2
3
3
use crate :: {
4
- * ,
5
4
problem_registry:: * ,
6
- procedure:: {
7
- * ,
8
- writer_schema:: * ,
9
- }
5
+ procedure:: { writer_schema:: * , * } ,
6
+ * ,
10
7
} ;
11
8
use std:: collections:: HashMap ;
12
9
13
10
pub fn transpile (
14
11
problem : writer_schema:: Procedure ,
15
- ) -> Result < ( registered:: Procedure , HashMap < identifiers:: ResourceId , String > ) , RegistrationError > {
12
+ ) -> Result <
13
+ (
14
+ registered:: Procedure ,
15
+ HashMap < identifiers:: ResourceId , String > ,
16
+ ) ,
17
+ RegistrationError ,
18
+ > {
16
19
let mut name_to_id = HashMap :: new ( ) ;
17
20
for resource in problem. resources . iter ( ) {
18
21
let name = match resource {
@@ -46,54 +49,72 @@ pub fn transpile(
46
49
for resource in problem. resources . iter ( ) {
47
50
match resource {
48
51
ResourceKind :: TextFile ( content) => {
49
- let dep_id = name_to_id. get ( & content. name )
50
- . ok_or ( RegistrationError :: InvalidSchema ( "TextFile name not found" . to_string ( ) ) ) ?
52
+ let dep_id = name_to_id
53
+ . get ( & content. name )
54
+ . ok_or ( RegistrationError :: InvalidSchema (
55
+ "TextFile name not found" . to_string ( ) ,
56
+ ) ) ?
51
57
. clone ( ) ;
52
58
let text = registered:: Text {
53
- resource_id : content_to_id. get ( & content. content )
54
- . ok_or ( RegistrationError :: InvalidSchema ( "TextFile content not found" . to_string ( ) ) ) ?
59
+ resource_id : content_to_id
60
+ . get ( & content. content )
61
+ . ok_or ( RegistrationError :: InvalidSchema (
62
+ "TextFile content not found" . to_string ( ) ,
63
+ ) ) ?
55
64
. clone ( ) ,
56
65
dep_id : dep_id. clone ( ) ,
57
66
} ;
58
67
texts. push ( text) ;
59
- } ,
68
+ }
60
69
ResourceKind :: EmptyDirectory ( empty_dir) => {
61
- let dep_id = name_to_id. get ( & empty_dir. name )
62
- . ok_or ( RegistrationError :: InvalidSchema ( "EmptyDirectory name not found" . to_string ( ) ) ) ?
70
+ let dep_id = name_to_id
71
+ . get ( & empty_dir. name )
72
+ . ok_or ( RegistrationError :: InvalidSchema (
73
+ "EmptyDirectory name not found" . to_string ( ) ,
74
+ ) ) ?
63
75
. clone ( ) ;
64
76
let empty_directory = registered:: EmptyDirectory {
65
77
dep_id : dep_id. clone ( ) ,
66
78
} ;
67
79
empty_directories. push ( empty_directory) ;
68
- } ,
80
+ }
69
81
ResourceKind :: RuntimeTextFile ( runtime_text) => {
70
- let dep_id = name_to_id. get ( & runtime_text. name )
71
- . ok_or ( RegistrationError :: InvalidSchema ( "RuntimeText name not found" . to_string ( ) ) ) ?
82
+ let dep_id = name_to_id
83
+ . get ( & runtime_text. name )
84
+ . ok_or ( RegistrationError :: InvalidSchema (
85
+ "RuntimeText name not found" . to_string ( ) ,
86
+ ) ) ?
72
87
. clone ( ) ;
73
88
let runtime_text = registered:: RuntimeText {
74
89
label : runtime_text. label . clone ( ) ,
75
90
dep_id : dep_id. clone ( ) ,
76
91
} ;
77
92
runtime_texts. push ( runtime_text) ;
78
- } ,
93
+ }
79
94
}
80
95
}
81
96
let mut executions = Vec :: new ( ) ;
82
97
for execution in problem. executions . iter ( ) {
83
98
let script = execution. script_name . clone ( ) ;
84
99
let mut dependencies = Vec :: new ( ) ;
85
100
for dep in execution. depends_on . iter ( ) {
86
- let dep_id = name_to_id. get ( & dep. ref_to )
87
- . ok_or ( RegistrationError :: InvalidSchema ( "Dependency name not found" . to_string ( ) ) ) ?
101
+ let dep_id = name_to_id
102
+ . get ( & dep. ref_to )
103
+ . ok_or ( RegistrationError :: InvalidSchema (
104
+ "Dependency name not found" . to_string ( ) ,
105
+ ) ) ?
88
106
. clone ( ) ;
89
107
let depends_on = registered:: DependsOn {
90
108
dep_id : dep_id. clone ( ) ,
91
109
envvar_name : dep. envvar_name . clone ( ) ,
92
110
} ;
93
111
dependencies. push ( depends_on) ;
94
112
}
95
- let dep_id = name_to_id. get ( & execution. name )
96
- . ok_or ( RegistrationError :: InvalidSchema ( "Execution name not found" . to_string ( ) ) ) ?
113
+ let dep_id = name_to_id
114
+ . get ( & execution. name )
115
+ . ok_or ( RegistrationError :: InvalidSchema (
116
+ "Execution name not found" . to_string ( ) ,
117
+ ) ) ?
97
118
. clone ( ) ;
98
119
let priority = 0 ;
99
120
let execution = registered:: Execution {
@@ -112,6 +133,9 @@ pub fn transpile(
112
133
} ;
113
134
Ok ( (
114
135
procedure,
115
- content_to_id. iter ( ) . map ( |( k, v) | ( v. clone ( ) , k. clone ( ) ) ) . collect ( )
136
+ content_to_id
137
+ . iter ( )
138
+ . map ( |( k, v) | ( v. clone ( ) , k. clone ( ) ) )
139
+ . collect ( ) ,
116
140
) )
117
- }
141
+ }
0 commit comments