1
1
use std:: { env, fs, ops:: Range , path:: Path } ;
2
2
3
- fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
3
+ type Result < T > = std:: result:: Result < T , Box < dyn std:: error:: Error > > ;
4
+
5
+ fn main ( ) -> Result < ( ) > {
6
+ if let Err ( err) = generate ( ) {
7
+ if char:: UNICODE_VERSION == ( 13 , 0 , 0 ) {
8
+ // if unable to generate the script from data files (e.g. if the
9
+ // unicode website is down ... ) get a pre generated version
10
+ // from a github gist
11
+ // This should not be needed ugh
12
+ pre_generated ( ) ?;
13
+ } else {
14
+ return Err ( err) ;
15
+ }
16
+ }
17
+
18
+ Ok ( ( ) )
19
+ }
20
+
21
+ fn generate ( ) -> Result < ( ) > {
4
22
let out_dir = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ;
5
23
let dest_path = Path :: new ( & out_dir) . join ( "unicode.rs" ) ;
6
24
@@ -169,7 +187,7 @@ impl GeneralCategory {
169
187
}
170
188
171
189
// retrieve and parse the unicodedata.txt file
172
- fn unicode_data ( ) -> Result < Vec < ( u32 , GeneralCategory ) > , Box < dyn std :: error :: Error > > {
190
+ fn unicode_data ( ) -> Result < Vec < ( u32 , GeneralCategory ) > > {
173
191
let unicode_version = format ! (
174
192
"{}.{}.{}" ,
175
193
char :: UNICODE_VERSION . 0 ,
@@ -194,7 +212,7 @@ fn unicode_data() -> Result<Vec<(u32, GeneralCategory)>, Box<dyn std::error::Err
194
212
}
195
213
196
214
/// retrieve and parse the unicode case fold data
197
- fn casefold_data ( ) -> Result < Vec < ( String , String , String ) > , Box < dyn std :: error :: Error > > {
215
+ fn casefold_data ( ) -> Result < Vec < ( String , String , String ) > > {
198
216
let unicode_version = format ! (
199
217
"{}.{}.{}" ,
200
218
char :: UNICODE_VERSION . 0 ,
@@ -246,3 +264,15 @@ fn compress_data(input: &[u32]) -> Vec<Range<char>> {
246
264
247
265
output
248
266
}
267
+
268
+ fn pre_generated ( ) -> Result < ( ) > {
269
+ let out_dir = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ;
270
+ let dest_path = Path :: new ( & out_dir) . join ( "unicode.rs" ) ;
271
+
272
+ let pre_generated = reqwest:: blocking:: get ( "https://gist.githubusercontent.com/OrangeBacon/ff701218dc0d77bb45b949c0e4bf4776/raw/7d262049ba26aeca022685ca91396e33b0196534/unicode13.0.0.rs" ) ?
273
+ . text ( ) ?;
274
+
275
+ fs:: write ( & dest_path, pre_generated) ?;
276
+
277
+ Ok ( ( ) )
278
+ }
0 commit comments