Skip to content

Commit cfe6457

Browse files
committed
chore: format using GA_HAT rules
1 parent 75a1b3c commit cfe6457

File tree

1 file changed

+120
-108
lines changed

1 file changed

+120
-108
lines changed

src/main.rs

Lines changed: 120 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use core::cmp::{max, min};
1313
use core::f32;
1414

1515
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};
1818

1919
// ----------------------------------------------------------------------------
2020
pub use std::{env, fs};
@@ -51,61 +51,63 @@ macro_rules! ipsum {
5151

5252
// ----------------------------------------------------------------------------
5353
lorem!(
54-
const _: u8 = 0;
54+
const _: u8 = 0;
5555
);
5656
ipsum!(
57-
const _: u8 = 0;
57+
const _: u8 = 0;
5858
);
5959

6060
// ----------------------------------------------------------------------------
61-
extern "C" {
62-
static mut LOREM_EXTERN: i32;
61+
extern {
62+
static mut LOREM_EXTERN: i32;
6363
}
6464

6565
// ----------------------------------------------------------------------------
6666
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
6767
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 },
7171
}
7272

7373
#[derive(Default, Debug, Serialize, Deserialize)]
7474
pub struct FieldAlign {
75-
x: u32,
76-
yy: u32,
77-
zzz: u32,
75+
x: u32,
76+
yy: u32,
77+
zzz: u32,
7878
}
7979

8080
#[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+
}
8286

8387
#[derive(Default, Debug, Serialize, Deserialize)]
8488
pub struct Bar {
85-
ipsum: i32,
86-
dolor: i32,
87-
sit: i32,
89+
ipsum: i32,
90+
dolor: i32,
91+
sit: i32,
8892
}
8993

9094
// ----------------------------------------------------------------------------
91-
pub fn generic_compressed<Ipsum: Display+Debug=usize>() {}
95+
pub fn generic_compressed<Ipsum: Display + Debug = usize>() {}
9296
pub fn generic_wide<Ipsum: Display + Debug = usize>() {}
9397

9498
pub trait LoremTrait<T> {}
9599

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 {}
101101

102102
impl<T> LoremTrait<T> for std::collections::VecDeque<T> where Option<T>: Clone {}
103103

104104
struct DummyIter;
105105
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;
109111
}
110112

111113
// ----------------------------------------------------------------------------
@@ -122,7 +124,9 @@ impl Iterator for DummyIter {
122124
/// );
123125
/// # fn add_one(x: i32) -> i32 { x + 1 }
124126
/// ```
125-
pub fn add_one(x: i32) -> i32 { x + 1 }
127+
pub fn add_one(x: i32) -> i32 {
128+
x + 1
129+
}
126130

127131
// ----------------------------------------------------------------------------
128132
/* 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 }
134138
// ----------------------------------------------------------------------------
135139
#[allow(unused_mut)]
136140
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+
}
144148
}
145149

146150
// ----------------------------------------------------------------------------
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+
];
148158

149159
// ----------------------------------------------------------------------------
150160
const LONG_STR: &str = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
151161

152162
// ----------------------------------------------------------------------------
153163
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 }
158170
}
159171

160172
// ----------------------------------------------------------------------------
161173
#[allow(clippy::needless_collect)]
162174
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";
165177

166-
foo(ctx, |param: i32| {
167-
let _ = param + 1;
168-
param
169-
});
178+
foo(ctx, |param: i32| {
179+
let _ = param + 1;
180+
param
181+
});
170182

171-
foo(ctx, Bar { ipsum: 1, dolor: 2, sit: 3 });
183+
foo(ctx, Bar { ipsum: 1, dolor: 2, sit: 3 });
172184

173-
foo(ctx, &[
174-
1, 2, 3, 4, 5,
175-
]);
185+
foo(ctx, &[1, 2, 3, 4, 5]);
176186

177-
foo(ctx, vec![1, 2, 3, 4, 5]);
187+
foo(ctx, vec![1, 2, 3, 4, 5]);
178188
}
179189

180190
// ----------------------------------------------------------------------------
181191
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+
}
195205
}
196206

197207
// ----------------------------------------------------------------------------
198-
fn single_line_things() -> i32 { 42 }
208+
fn single_line_things() -> i32 {
209+
42
210+
}
199211

200212
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") }
204216
}
205217

206-
fn return_semicolon() -> i32 { return 0; }
218+
fn return_semicolon() -> i32 {
219+
return 0;
220+
}
207221

208222
// ----------------------------------------------------------------------------
209-
fn nested_parens() { (((((println!("nested")))))); }
223+
fn nested_parens() {
224+
(println!("nested"));
225+
}
210226

211227
// ----------------------------------------------------------------------------
212228
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(())
219235
}
220236

221237
// ----------------------------------------------------------------------------
222238
#[doc = "Example item documentation via attribute"]
223239
pub struct DocAttrItem;
224240

225241
// ----------------------------------------------------------------------------
226-
#[cfg(any())] use std::marker::PhantomData;
242+
#[cfg(any())]
243+
use std::marker::PhantomData;
227244

228245
// ----------------------------------------------------------------------------
229246
#[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+
}
238250

239251
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 };
241253
}
242254

243255
// ----------------------------------------------------------------------------
244256
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 };
246258
}
247259

248260
// ----------------------------------------------------------------------------
249261
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};
253265
}
254266

255267
// ----------------------------------------------------------------------------
256268
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();
265277

266-
// ----------------------------------------------------------
267-
let _hex_sum = HEXES.iter().sum::<u64>();
278+
// ----------------------------------------------------------
279+
let _hex_sum = HEXES.iter().sum::<u64>();
268280

269-
// ----------------------------------------------------------
270-
let _bar = Bar { ipsum: 10, dolor: 20, sit: 30 };
281+
// ----------------------------------------------------------
282+
let _bar = Bar { ipsum: 10, dolor: 20, sit: 30 };
271283

272-
// ----------------------------------------------------------
273-
let _fa = FieldAlign { x: 1, yy: 2, zzz: 3 };
284+
// ----------------------------------------------------------
285+
let _fa = FieldAlign { x: 1, yy: 2, zzz: 3 };
274286

275-
// ----------------------------------------------------------
276-
nested_parens();
287+
// ----------------------------------------------------------
288+
nested_parens();
277289

278-
// ----------------------------------------------------------
279-
let _arr = [1, 2, 3, 1234567890];
290+
// ----------------------------------------------------------
291+
let _arr = [1, 2, 3, 1234567890];
280292

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<_>>();
283295
}

0 commit comments

Comments
 (0)