@@ -32,7 +32,15 @@ fn strip_comments(mut line: String) -> String {
32
32
// to this zone, as a string representation of a static slice.
33
33
fn format_rest ( rest : Vec < ( i64 , FixedTimespan ) > ) -> String {
34
34
let mut ret = "&[\n " . to_string ( ) ;
35
- for ( start, FixedTimespan { utc_offset, dst_offset, name } ) in rest {
35
+ for (
36
+ start,
37
+ FixedTimespan {
38
+ utc_offset,
39
+ dst_offset,
40
+ name,
41
+ } ,
42
+ ) in rest
43
+ {
36
44
ret. push_str ( & format ! (
37
45
" ({start}, FixedTimespan {{ \
38
46
utc_offset: {utc}, dst_offset: {dst}, name: \" {name}\" \
@@ -53,7 +61,12 @@ fn format_rest(rest: Vec<(i64, FixedTimespan)>) -> String {
53
61
fn convert_bad_chars ( name : & str ) -> String {
54
62
let name = name. replace ( '/' , "__" ) . replace ( '+' , "Plus" ) ;
55
63
if let Some ( pos) = name. find ( '-' ) {
56
- if name[ pos + 1 ..] . chars ( ) . next ( ) . map ( char:: is_numeric) . unwrap_or ( false ) {
64
+ if name[ pos + 1 ..]
65
+ . chars ( )
66
+ . next ( )
67
+ . map ( char:: is_numeric)
68
+ . unwrap_or ( false )
69
+ {
57
70
name. replace ( '-' , "Minus" )
58
71
} else {
59
72
name. replace ( '-' , "" )
@@ -67,8 +80,15 @@ fn convert_bad_chars(name: &str) -> String {
67
80
// database. The `Wrap` wrapper in the `timezone_impl` module then implements
68
81
// TimeZone for any contained struct that implements `Timespans`.
69
82
fn write_timezone_file ( timezone_file : & mut File , table : & Table ) -> io:: Result < ( ) > {
70
- let zones = table. zonesets . keys ( ) . chain ( table. links . keys ( ) ) . collect :: < BTreeSet < _ > > ( ) ;
71
- writeln ! ( timezone_file, "use core::fmt::{{self, Debug, Display, Formatter}};" , ) ?;
83
+ let zones = table
84
+ . zonesets
85
+ . keys ( )
86
+ . chain ( table. links . keys ( ) )
87
+ . collect :: < BTreeSet < _ > > ( ) ;
88
+ writeln ! (
89
+ timezone_file,
90
+ "use core::fmt::{{self, Debug, Display, Formatter}};" ,
91
+ ) ?;
72
92
writeln ! ( timezone_file, "use core::str::FromStr;\n " , ) ?;
73
93
writeln ! (
74
94
timezone_file,
@@ -83,7 +103,10 @@ fn write_timezone_file(timezone_file: &mut File, table: &Table) -> io::Result<()
83
103
/// for details."
84
104
) ?;
85
105
writeln ! ( timezone_file, "#[derive(Clone, Copy, PartialEq, Eq, Hash)]" ) ?;
86
- writeln ! ( timezone_file, r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"# ) ?;
106
+ writeln ! (
107
+ timezone_file,
108
+ r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#
109
+ ) ?;
87
110
writeln ! ( timezone_file, "pub enum Tz {{" ) ?;
88
111
for zone in & zones {
89
112
let zone_name = convert_bad_chars ( zone) ;
@@ -100,20 +123,29 @@ fn write_timezone_file(timezone_file: &mut File, table: &Table) -> io::Result<()
100
123
for zone in & zones {
101
124
map. entry ( zone, & format ! ( "Tz::{}" , convert_bad_chars( zone) ) ) ;
102
125
}
103
- writeln ! ( timezone_file, "static TIMEZONES: ::phf::Map<&'static str, Tz> = \n {};" , map. build( ) ) ?;
126
+ writeln ! (
127
+ timezone_file,
128
+ "static TIMEZONES: ::phf::Map<&'static str, Tz> = \n {};" ,
129
+ map. build( )
130
+ ) ?;
104
131
105
132
#[ cfg( feature = "case-insensitive" ) ]
106
133
{
107
134
writeln ! ( timezone_file, "use uncased::UncasedStr;\n " , ) ?;
108
135
let mut map = phf_codegen:: Map :: new ( ) ;
109
136
for zone in & zones {
110
- map. entry ( uncased:: UncasedStr :: new ( zone) , & format ! ( "Tz::{}" , convert_bad_chars( zone) ) ) ;
137
+ map. entry (
138
+ uncased:: UncasedStr :: new ( zone) ,
139
+ & format ! ( "Tz::{}" , convert_bad_chars( zone) ) ,
140
+ ) ;
111
141
}
112
142
writeln ! (
113
143
timezone_file,
114
144
"static TIMEZONES_UNCASED: ::phf::Map<&'static uncased::UncasedStr, Tz> = \n {};" ,
115
145
// FIXME(petrosagg): remove this once rust-phf/rust-phf#232 is released
116
- map. build( ) . to_string( ) . replace( "::std::mem::transmute" , "::core::mem::transmute" )
146
+ map. build( )
147
+ . to_string( )
148
+ . replace( "::std::mem::transmute" , "::core::mem::transmute" )
117
149
) ?;
118
150
}
119
151
@@ -242,7 +274,11 @@ pub static TZ_VARIANTS: [Tz; {num}] = [
242
274
num = zones. len( )
243
275
) ?;
244
276
for zone in & zones {
245
- writeln ! ( timezone_file, " Tz::{zone}," , zone = convert_bad_chars( zone) ) ?;
277
+ writeln ! (
278
+ timezone_file,
279
+ " Tz::{zone}," ,
280
+ zone = convert_bad_chars( zone)
281
+ ) ?;
246
282
}
247
283
write ! ( timezone_file, "];" ) ?;
248
284
Ok ( ( ) )
@@ -252,7 +288,10 @@ pub static TZ_VARIANTS: [Tz; {num}] = [
252
288
// instead of having to use chrono_tz::timezones::Europe__London
253
289
fn write_directory_file ( directory_file : & mut File , table : & Table , version : & str ) -> io:: Result < ( ) > {
254
290
// expose the underlying IANA TZDB version
255
- writeln ! ( directory_file, "pub const IANA_TZDB_VERSION : &str = \" {version}\" ;\n " ) ?;
291
+ writeln ! (
292
+ directory_file,
293
+ "pub const IANA_TZDB_VERSION : &str = \" {version}\" ;\n "
294
+ ) ?;
256
295
// add the `loose' zone definitions first
257
296
writeln ! ( directory_file, "use crate::timezones::Tz;\n " ) ?;
258
297
let zones = table
@@ -263,7 +302,11 @@ fn write_directory_file(directory_file: &mut File, table: &Table, version: &str)
263
302
. collect :: < BTreeSet < _ > > ( ) ;
264
303
for zone in zones {
265
304
let zone = convert_bad_chars ( zone) ;
266
- writeln ! ( directory_file, "pub const {name} : Tz = Tz::{name};" , name = zone) ?;
305
+ writeln ! (
306
+ directory_file,
307
+ "pub const {name} : Tz = Tz::{name};" ,
308
+ name = zone
309
+ ) ?;
267
310
}
268
311
writeln ! ( directory_file) ?;
269
312
@@ -279,7 +322,11 @@ fn write_directory_file(directory_file: &mut File, table: &Table, version: &str)
279
322
match child {
280
323
Child :: Submodule ( name) => {
281
324
let submodule_name = convert_bad_chars ( name) ;
282
- writeln ! ( directory_file, " pub mod {name} {{" , name = submodule_name) ?;
325
+ writeln ! (
326
+ directory_file,
327
+ " pub mod {name} {{" ,
328
+ name = submodule_name
329
+ ) ?;
283
330
writeln ! ( directory_file, " use crate::timezones::Tz;\n " , ) ?;
284
331
let full_name = entry. name . to_string ( ) + "/" + name;
285
332
for entry in table. structure ( ) {
@@ -428,7 +475,9 @@ mod filter {
428
475
}
429
476
430
477
// Actually do the filtering.
431
- table. links . retain ( |k, v| keep. contains ( k) || keep. contains ( v) ) ;
478
+ table
479
+ . links
480
+ . retain ( |k, v| keep. contains ( k) || keep. contains ( v) ) ;
432
481
433
482
table
434
483
. zonesets
0 commit comments