@@ -13,8 +13,8 @@ use core::cmp::{max, min};
13
13
use core:: f32;
14
14
15
15
use regex:: { Captures , Regex } ;
16
- use serde:: { de :: DeserializeOwned , Deserialize , Serialize } ;
17
- use serde_json:: { self , json , Value } ;
16
+ use serde:: { Deserialize , Serialize , de :: DeserializeOwned } ;
17
+ use serde_json:: { self , Value , json } ;
18
18
19
19
// ----------------------------------------------------------------------------
20
20
pub use std:: { env, fs} ;
@@ -51,61 +51,63 @@ macro_rules! ipsum {
51
51
52
52
// ----------------------------------------------------------------------------
53
53
lorem ! (
54
- const _: u8 = 0 ;
54
+ const _: u8 = 0 ;
55
55
) ;
56
56
ipsum ! (
57
- const _: u8 = 0 ;
57
+ const _: u8 = 0 ;
58
58
) ;
59
59
60
60
// ----------------------------------------------------------------------------
61
- extern "C" {
62
- static mut LOREM_EXTERN : i32 ;
61
+ extern {
62
+ static mut LOREM_EXTERN : i32 ;
63
63
}
64
64
65
65
// ----------------------------------------------------------------------------
66
66
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
67
67
pub enum EnumLorem {
68
- Ipsum ,
69
- Dolor ( bool ) ,
70
- Sit { amet : u32 , adipiscing : u64 } ,
68
+ Ipsum ,
69
+ Dolor ( bool ) ,
70
+ Sit { amet : u32 , adipiscing : u64 } ,
71
71
}
72
72
73
73
#[ derive( Default , Debug , Serialize , Deserialize ) ]
74
74
pub struct FieldAlign {
75
- x : u32 ,
76
- yy : u32 ,
77
- zzz : u32 ,
75
+ x : u32 ,
76
+ yy : u32 ,
77
+ zzz : u32 ,
78
78
}
79
79
80
80
#[ derive( Default , Debug , Serialize , Deserialize ) ]
81
- pub struct Foo { x : i32 , y : i32 , z : i32 }
81
+ pub struct Foo {
82
+ x : i32 ,
83
+ y : i32 ,
84
+ z : i32 ,
85
+ }
82
86
83
87
#[ derive( Default , Debug , Serialize , Deserialize ) ]
84
88
pub struct Bar {
85
- ipsum : i32 ,
86
- dolor : i32 ,
87
- sit : i32 ,
89
+ ipsum : i32 ,
90
+ dolor : i32 ,
91
+ sit : i32 ,
88
92
}
89
93
90
94
// ----------------------------------------------------------------------------
91
- pub fn generic_compressed < Ipsum : Display + Debug = usize > ( ) { }
95
+ pub fn generic_compressed < Ipsum : Display + Debug = usize > ( ) { }
92
96
pub fn generic_wide < Ipsum : Display + Debug = usize > ( ) { }
93
97
94
98
pub trait LoremTrait < T > { }
95
99
96
- impl < T > LoremTrait < T > for Vec < T >
97
- where
98
- Option < T > : Clone ,
99
- {
100
- }
100
+ impl < T > LoremTrait < T > for Vec < T > where Option < T > : Clone { }
101
101
102
102
impl < T > LoremTrait < T > for std:: collections:: VecDeque < T > where Option < T > : Clone { }
103
103
104
104
struct DummyIter ;
105
105
impl Iterator for DummyIter {
106
- const SIZE : usize = 0123456789 ;
107
- fn next ( & mut self ) -> Option < Self :: Item > { None }
108
- type Item = i32 ;
106
+ const SIZE : usize = 0123456789 ;
107
+ fn next ( & mut self ) -> Option < Self :: Item > {
108
+ None
109
+ }
110
+ type Item = i32 ;
109
111
}
110
112
111
113
// ----------------------------------------------------------------------------
@@ -122,7 +124,9 @@ impl Iterator for DummyIter {
122
124
/// );
123
125
/// # fn add_one(x: i32) -> i32 { x + 1 }
124
126
/// ```
125
- pub fn add_one ( x : i32 ) -> i32 { x + 1 }
127
+ pub fn add_one ( x : i32 ) -> i32 {
128
+ x + 1
129
+ }
126
130
127
131
// ----------------------------------------------------------------------------
128
132
/* This is a block comment that rustfmt can optionally convert into a line
@@ -134,150 +138,158 @@ pub fn add_one(x: i32) -> i32 { x + 1 }
134
138
// ----------------------------------------------------------------------------
135
139
#[ allow( unused_mut) ]
136
140
fn ranges_demo ( ) {
137
- let mut a = 0 ..10 ;
138
- let b = 0 ..=10 ;
139
- let v: Vec < i32 > = ( 0 ..10 ) . collect ( ) ;
140
- match 3 {
141
- 1 ..5 => ( ) ,
142
- _ => ( ) ,
143
- }
141
+ let mut a = 0 ..10 ;
142
+ let b = 0 ..=10 ;
143
+ let v: Vec < i32 > = ( 0 ..10 ) . collect ( ) ;
144
+ match 3 {
145
+ 1 ..5 => ( ) ,
146
+ _ => ( ) ,
147
+ }
144
148
}
145
149
146
150
// ----------------------------------------------------------------------------
147
- const HEXES : [ u64 ; 5 ] = [ 0x0000_0000_0000_0000 , 0xAAAA_AAAA_AAAA_AAAA , 0xbbbb_bbbb_bbbb_bbbb , 0xCCCC_CCCC_CCCC_CCCC , 0xDDDD_DDDD_DDDD_DDDD ] ;
151
+ const HEXES : [ u64 ; 5 ] = [
152
+ 0x0000_0000_0000_0000 ,
153
+ 0xAAAA_AAAA_AAAA_AAAA ,
154
+ 0xbbbb_bbbb_bbbb_bbbb ,
155
+ 0xCCCC_CCCC_CCCC_CCCC ,
156
+ 0xDDDD_DDDD_DDDD_DDDD ,
157
+ ] ;
148
158
149
159
// ----------------------------------------------------------------------------
150
160
const LONG_STR : & str = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing" ;
151
161
152
162
// ----------------------------------------------------------------------------
153
163
fn make_foo ( ) -> Foo {
154
- let x = 1 ; let y = 2 ; let z = 3 ;
155
- let a = Foo { x, y, z } ; // shorthand
156
- let b = Foo { x : x, y : y, z : z } ; // no shorthand
157
- if x > 0 { a } else { b }
164
+ let x = 1 ;
165
+ let y = 2 ;
166
+ let z = 3 ;
167
+ let a = Foo { x, y, z } ; // shorthand
168
+ let b = Foo { x : x, y : y, z : z } ; // no shorthand
169
+ if x > 0 { a } else { b }
158
170
}
159
171
160
172
// ----------------------------------------------------------------------------
161
173
#[ allow( clippy:: needless_collect) ]
162
174
fn overflow_demo ( ) {
163
- fn foo < T > ( _ctx : & str , _t : T ) { }
164
- let ctx = "ctx" ;
175
+ fn foo < T > ( _ctx : & str , _t : T ) { }
176
+ let ctx = "ctx" ;
165
177
166
- foo ( ctx, |param : i32 | {
167
- let _ = param + 1 ;
168
- param
169
- } ) ;
178
+ foo ( ctx, |param : i32 | {
179
+ let _ = param + 1 ;
180
+ param
181
+ } ) ;
170
182
171
- foo ( ctx, Bar { ipsum : 1 , dolor : 2 , sit : 3 } ) ;
183
+ foo ( ctx, Bar { ipsum : 1 , dolor : 2 , sit : 3 } ) ;
172
184
173
- foo ( ctx, & [
174
- 1 , 2 , 3 , 4 , 5 ,
175
- ] ) ;
185
+ foo ( ctx, & [ 1 , 2 , 3 , 4 , 5 ] ) ;
176
186
177
- foo ( ctx, vec ! [ 1 , 2 , 3 , 4 , 5 ] ) ;
187
+ foo ( ctx, vec ! [ 1 , 2 , 3 , 4 , 5 ] ) ;
178
188
}
179
189
180
190
// ----------------------------------------------------------------------------
181
191
fn match_and_closure_demo ( x : i32 ) {
182
- let _ = Some ( x) . and_then ( |maybe| match maybe {
183
- 0 => Some ( 1 ) ,
184
- _ => None ,
185
- } ) ;
186
-
187
- match x {
188
- | 0 | 1 => println ! ( "small" ) ,
189
- 2 => {
190
- println ! ( "two" ) ;
191
- }
192
- 3 => println ! ( "three" ) ,
193
- _ => println ! ( "other" ) ,
194
- }
192
+ let _ = Some ( x) . and_then ( |maybe| match maybe {
193
+ 0 => Some ( 1 ) ,
194
+ _ => None ,
195
+ } ) ;
196
+
197
+ match x {
198
+ 0 | 1 => println ! ( "small" ) ,
199
+ 2 => {
200
+ println ! ( "two" ) ;
201
+ }
202
+ 3 => println ! ( "three" ) ,
203
+ _ => println ! ( "other" ) ,
204
+ }
195
205
}
196
206
197
207
// ----------------------------------------------------------------------------
198
- fn single_line_things ( ) -> i32 { 42 }
208
+ fn single_line_things ( ) -> i32 {
209
+ 42
210
+ }
199
211
200
212
fn let_else_demo ( ) {
201
- let opt = Some ( 10 ) ;
202
- let Some ( v) = opt else { return } ;
203
- if v > 5 { println ! ( "gt5" ) } else { println ! ( "le5" ) }
213
+ let opt = Some ( 10 ) ;
214
+ let Some ( v) = opt else { return } ;
215
+ if v > 5 { println ! ( "gt5" ) } else { println ! ( "le5" ) }
204
216
}
205
217
206
- fn return_semicolon ( ) -> i32 { return 0 ; }
218
+ fn return_semicolon ( ) -> i32 {
219
+ return 0 ;
220
+ }
207
221
208
222
// ----------------------------------------------------------------------------
209
- fn nested_parens ( ) { ( ( ( ( ( println ! ( "nested" ) ) ) ) ) ) ; }
223
+ fn nested_parens ( ) {
224
+ ( println ! ( "nested" ) ) ;
225
+ }
210
226
211
227
// ----------------------------------------------------------------------------
212
228
fn try_demo ( ) -> Result < ( ) , io:: Error > {
213
- use std:: fs:: File ;
214
- use std:: io:: Read ;
215
- let mut s = String :: new ( ) ;
216
- let mut f = File :: open ( "/dev/null" ) ?;
217
- f. read_to_string ( & mut s) ;
218
- Ok ( ( ) )
229
+ use std:: fs:: File ;
230
+ use std:: io:: Read ;
231
+ let mut s = String :: new ( ) ;
232
+ let mut f = File :: open ( "/dev/null" ) ?;
233
+ f. read_to_string ( & mut s) ;
234
+ Ok ( ( ) )
219
235
}
220
236
221
237
// ----------------------------------------------------------------------------
222
238
#[ doc = "Example item documentation via attribute" ]
223
239
pub struct DocAttrItem ;
224
240
225
241
// ----------------------------------------------------------------------------
226
- #[ cfg( any( ) ) ] use std:: marker:: PhantomData ;
242
+ #[ cfg( any( ) ) ]
243
+ use std:: marker:: PhantomData ;
227
244
228
245
// ----------------------------------------------------------------------------
229
246
#[ allow( clippy:: too_many_arguments) ]
230
- fn many_args (
231
- a : i32 ,
232
- b : i32 ,
233
- c : i32 ,
234
- d : i32 ,
235
- e : i32 ,
236
- f : i32 ,
237
- ) -> i32 { a + b + c + d + e + f }
247
+ fn many_args ( a : i32 , b : i32 , c : i32 , d : i32 , e : i32 , f : i32 ) -> i32 {
248
+ a + b + c + d + e + f
249
+ }
238
250
239
251
fn destructuring ( ) {
240
- let Foo { x, y, z } = Foo { x : 1 , y : 2 , z : 3 } ;
252
+ let Foo { x, y, z } = Foo { x : 1 , y : 2 , z : 3 } ;
241
253
}
242
254
243
255
// ----------------------------------------------------------------------------
244
256
fn spacing_demo < T : Eq > ( t : T ) {
245
- let _lorem: Bar = Bar { ipsum : 1 , dolor : 2 , sit : 3 } ;
257
+ let _lorem: Bar = Bar { ipsum : 1 , dolor : 2 , sit : 3 } ;
246
258
}
247
259
248
260
// ----------------------------------------------------------------------------
249
261
mod reorder_demo {
250
- use std:: time :: { Duration , SystemTime } ;
251
- use std:: cmp :: { Ordering , Reverse } ;
252
- use std:: { mem, ptr} ;
262
+ use std:: cmp :: { Ordering , Reverse } ;
263
+ use std:: time :: { Duration , SystemTime } ;
264
+ use std:: { mem, ptr} ;
253
265
}
254
266
255
267
// ----------------------------------------------------------------------------
256
268
fn main ( ) {
257
- // ----------------------------------------------------------
258
- let _s = LONG_STR ;
259
- let _foo = make_foo ( ) ;
260
- overflow_demo ( ) ;
261
- match_and_closure_demo ( 2 ) ;
262
- let_else_demo ( ) ;
263
- ranges_demo ( ) ;
264
- let _ = try_demo ( ) ;
269
+ // ----------------------------------------------------------
270
+ let _s = LONG_STR ;
271
+ let _foo = make_foo ( ) ;
272
+ overflow_demo ( ) ;
273
+ match_and_closure_demo ( 2 ) ;
274
+ let_else_demo ( ) ;
275
+ ranges_demo ( ) ;
276
+ let _ = try_demo ( ) ;
265
277
266
- // ----------------------------------------------------------
267
- let _hex_sum = HEXES . iter ( ) . sum :: < u64 > ( ) ;
278
+ // ----------------------------------------------------------
279
+ let _hex_sum = HEXES . iter ( ) . sum :: < u64 > ( ) ;
268
280
269
- // ----------------------------------------------------------
270
- let _bar = Bar { ipsum : 10 , dolor : 20 , sit : 30 } ;
281
+ // ----------------------------------------------------------
282
+ let _bar = Bar { ipsum : 10 , dolor : 20 , sit : 30 } ;
271
283
272
- // ----------------------------------------------------------
273
- let _fa = FieldAlign { x : 1 , yy : 2 , zzz : 3 } ;
284
+ // ----------------------------------------------------------
285
+ let _fa = FieldAlign { x : 1 , yy : 2 , zzz : 3 } ;
274
286
275
- // ----------------------------------------------------------
276
- nested_parens ( ) ;
287
+ // ----------------------------------------------------------
288
+ nested_parens ( ) ;
277
289
278
- // ----------------------------------------------------------
279
- let _arr = [ 1 , 2 , 3 , 1234567890 ] ;
290
+ // ----------------------------------------------------------
291
+ let _arr = [ 1 , 2 , 3 , 1234567890 ] ;
280
292
281
- // ----------------------------------------------------------
282
- let _v = ( 0 ..10 ) . map ( |x| x + 1 ) . filter ( |x| x % 2 == 0 ) . collect :: < Vec < _ > > ( ) ;
293
+ // ----------------------------------------------------------
294
+ let _v = ( 0 ..10 ) . map ( |x| x + 1 ) . filter ( |x| x % 2 == 0 ) . collect :: < Vec < _ > > ( ) ;
283
295
}
0 commit comments