Skip to content

Commit ec90a50

Browse files
authored
chore: add rust formatter (doocs#1946)
close doocs#1853
1 parent 160b013 commit ec90a50

File tree

1,228 files changed

+6910
-5539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,228 files changed

+6910
-5539
lines changed

.github/workflows/pr-checker.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
2020
我们项目中各种编程语言代码(包括文档)所采用的格式化工具不同,提交 pr 之前必须确保代码、文档正确格式化。
2121
22-
- .{md,js,ts,php,sql} 采用 prettier
22+
- .{md,js,ts,php,sql,rs} 采用 prettier
2323
- .{c,cpp,java} 采用 clang-format
2424
- .{py} 采用 black
2525
- .{go} 采用 gofmt
@@ -47,7 +47,7 @@ jobs:
4747
4848
We use different formatting tools for various programming languages (including documentation) in our project. You must ensure that the code and documentation are correctly formatted before submitting a pr.
4949
50-
- .{md,js,ts,php,sql} use prettier
50+
- .{md,js,ts,php,sql,rs} use prettier
5151
- .{c,cpp,java} use clang-format
5252
- .{py} use black
5353
- .{go} use gofmt

.github/workflows/prettier.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Run prettier
2626
run: |
2727
git config --global core.quotepath off
28-
changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.md$|\.js$|\.ts$|\.php|\.sql$' || true)
28+
changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.js$|\.ts$|\.php$|\.sql$|\.rs$|\.md$' || true)
2929
if [ -n "$changed_files" ]; then
3030
echo "Running prettier on the changed files"
3131
echo "$changed_files" | xargs -d '\n' npx prettier --write

basic/sorting/HeapSort/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,19 @@ fn sink(nums: &mut Vec<i32>, mut i: usize, n: usize) {
207207
fn main() -> io::Result<()> {
208208
let mut s = String::new();
209209
io::stdin().read_line(&mut s)?;
210-
let s: Vec<usize> = s.split(' ').map(|s| s.trim().parse().unwrap()).collect();
210+
let s: Vec<usize> = s
211+
.split(' ')
212+
.map(|s| s.trim().parse().unwrap())
213+
.collect();
211214
// let n = s[0];
212215
let m = s[1];
213216

214217
let mut nums = String::new();
215218
io::stdin().read_line(&mut nums)?;
216-
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
219+
let mut nums: Vec<i32> = nums
220+
.split(' ')
221+
.map(|s| s.trim().parse().unwrap())
222+
.collect();
217223

218224
heap_sort(&mut nums);
219225
for num in nums.iter().take(m) {

basic/sorting/InsertionSort/InsertionSort.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fn insertion_sort(nums: &mut Vec<i32>) {
33
for i in 1..n {
44
let mut j = i - 1;
55
let temp = nums[i];
6-
while j >= 0 as usize && nums[j] > temp {
6+
while j >= (0 as usize) && nums[j] > temp {
77
nums[j + 1] = nums[j];
88
j -= 1;
99
}

basic/sorting/InsertionSort/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn insertion_sort(nums: &mut Vec<i32>) {
136136
for i in 1..n {
137137
let mut j = i - 1;
138138
let temp = nums[i];
139-
while j >= 0 as usize && nums[j] > temp {
139+
while j >= (0 as usize) && nums[j] > temp {
140140
nums[j + 1] = nums[j];
141141
j -= 1;
142142
}

basic/sorting/MergeSort/Main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ fn main() -> io::Result<()> {
4343

4444
let mut nums = String::new();
4545
io::stdin().read_line(&mut nums)?;
46-
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
46+
let mut nums: Vec<i32> = nums
47+
.split(' ')
48+
.map(|s| s.trim().parse().unwrap())
49+
.collect();
4750

4851
merge_sort(&mut nums, 0, n - 1);
4952
for num in nums.iter() {

basic/sorting/MergeSort/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ fn main() -> io::Result<()> {
359359
360360
let mut nums = String::new();
361361
io::stdin().read_line(&mut nums)?;
362-
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
362+
let mut nums: Vec<i32> = nums
363+
.split(' ')
364+
.map(|s| s.trim().parse().unwrap())
365+
.collect();
363366
364367
merge_sort(&mut nums, 0, n - 1);
365368
for num in nums.iter() {

basic/sorting/QuickSort/Main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ fn main() -> io::Result<()> {
3737

3838
let mut nums = String::new();
3939
io::stdin().read_line(&mut nums)?;
40-
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
40+
let mut nums: Vec<i32> = nums
41+
.split(' ')
42+
.map(|s| s.trim().parse().unwrap())
43+
.collect();
4144

4245
quick_sort(&mut nums, 0, n - 1);
4346
for num in nums.iter() {

basic/sorting/QuickSort/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ fn main() -> io::Result<()> {
280280

281281
let mut nums = String::new();
282282
io::stdin().read_line(&mut nums)?;
283-
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
283+
let mut nums: Vec<i32> = nums
284+
.split(' ')
285+
.map(|s| s.trim().parse().unwrap())
286+
.collect();
284287

285288
quick_sort(&mut nums, 0, n - 1);
286289
for num in nums.iter() {

basic/sorting/ShellSort/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn shell_sort(nums: &mut Vec<i32>) {
104104
for i in gap..n {
105105
let mut j = i - gap;
106106
let temp = nums[i];
107-
while j >= 0 as usize && nums[j] > temp {
107+
while j >= (0 as usize) && nums[j] > temp {
108108
nums[j + gap] = nums[j];
109109
j -= gap;
110110
}

basic/sorting/ShellSort/ShellSort.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn shell_sort(nums: &mut Vec<i32>) {
55
for i in gap..n {
66
let mut j = i - gap;
77
let temp = nums[i];
8-
while j >= 0 as usize && nums[j] > temp {
8+
while j >= (0 as usize) && nums[j] > temp {
99
nums[j + gap] = nums[j];
1010
j -= gap;
1111
}

lcci/01.03.String to URL/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ impl Solution {
139139
s.chars()
140140
.take(length as usize)
141141
.map(|c| {
142-
if c == ' ' {
143-
"%20".to_string()
144-
} else {
145-
c.to_string()
146-
}
142+
if c == ' ' { "%20".to_string() } else { c.to_string() }
147143
})
148144
.collect()
149145
}

lcci/01.03.String to URL/README_EN.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ impl Solution {
136136
s.chars()
137137
.take(length as usize)
138138
.map(|c| {
139-
if c == ' ' {
140-
"%20".to_string()
141-
} else {
142-
c.to_string()
143-
}
139+
if c == ' ' { "%20".to_string() } else { c.to_string() }
144140
})
145141
.collect()
146142
}

lcci/01.09.String Rotation/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl Solution {
142142
}
143143
if is_pass {
144144
return true;
145-
};
145+
}
146146
}
147147
false
148148
}

lcci/01.09.String Rotation/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Solution {
115115
}
116116
if is_pass {
117117
return true;
118-
};
118+
}
119119
}
120120
false
121121
}

lcci/02.05.Sum Lists/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul
236236
impl Solution {
237237
pub fn add_two_numbers(
238238
mut l1: Option<Box<ListNode>>,
239-
mut l2: Option<Box<ListNode>>,
239+
mut l2: Option<Box<ListNode>>
240240
) -> Option<Box<ListNode>> {
241241
let mut dummy = Some(Box::new(ListNode::new(0)));
242242
let mut cur = dummy.as_mut();

lcci/02.05.Sum Lists/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul
231231
impl Solution {
232232
pub fn add_two_numbers(
233233
mut l1: Option<Box<ListNode>>,
234-
mut l2: Option<Box<ListNode>>,
234+
mut l2: Option<Box<ListNode>>
235235
) -> Option<Box<ListNode>> {
236236
let mut dummy = Some(Box::new(ListNode::new(0)));
237237
let mut cur = dummy.as_mut();

lcci/02.05.Sum Lists/Solution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
impl Solution {
22
pub fn add_two_numbers(
33
mut l1: Option<Box<ListNode>>,
4-
mut l2: Option<Box<ListNode>>,
4+
mut l2: Option<Box<ListNode>>
55
) -> Option<Box<ListNode>> {
66
let mut dummy = Some(Box::new(ListNode::new(0)));
77
let mut cur = dummy.as_mut();

lcci/03.02.Min Stack/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,11 @@ struct MinStack {
236236
min_stack: VecDeque<i32>,
237237
}
238238

239-
240239
/**
241240
* `&self` means the method takes an immutable reference.
242241
* If you need a mutable reference, change it to `&mut self` instead.
243242
*/
244243
impl MinStack {
245-
246244
/** initialize your data structure here. */
247245
fn new() -> Self {
248246
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
@@ -269,9 +267,7 @@ impl MinStack {
269267
fn get_min(&self) -> i32 {
270268
*self.min_stack.back().unwrap()
271269
}
272-
}
273-
274-
/**
270+
}/**
275271
* Your MinStack object will be instantiated and called as such:
276272
* let obj = MinStack::new();
277273
* obj.push(x);

lcci/03.02.Min Stack/README_EN.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,11 @@ struct MinStack {
236236
min_stack: VecDeque<i32>,
237237
}
238238

239-
240239
/**
241240
* `&self` means the method takes an immutable reference.
242241
* If you need a mutable reference, change it to `&mut self` instead.
243242
*/
244243
impl MinStack {
245-
246244
/** initialize your data structure here. */
247245
fn new() -> Self {
248246
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
@@ -269,9 +267,7 @@ impl MinStack {
269267
fn get_min(&self) -> i32 {
270268
*self.min_stack.back().unwrap()
271269
}
272-
}
273-
274-
/**
270+
}/**
275271
* Your MinStack object will be instantiated and called as such:
276272
* let obj = MinStack::new();
277273
* obj.push(x);

lcci/03.02.Min Stack/Solution.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ struct MinStack {
44
min_stack: VecDeque<i32>,
55
}
66

7-
87
/**
98
* `&self` means the method takes an immutable reference.
109
* If you need a mutable reference, change it to `&mut self` instead.
1110
*/
1211
impl MinStack {
13-
1412
/** initialize your data structure here. */
1513
fn new() -> Self {
1614
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
@@ -37,13 +35,11 @@ impl MinStack {
3735
fn get_min(&self) -> i32 {
3836
*self.min_stack.back().unwrap()
3937
}
40-
}
41-
42-
/**
38+
}/**
4339
* Your MinStack object will be instantiated and called as such:
4440
* let obj = MinStack::new();
4541
* obj.push(x);
4642
* obj.pop();
4743
* let ret_3: i32 = obj.top();
4844
* let ret_4: i32 = obj.get_min();
49-
*/
45+
*/

lcci/03.05.Sort of Stacks/README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,14 @@ func (s *SortedStack) IsEmpty() bool {
246246
```rust
247247
use std::collections::VecDeque;
248248
struct SortedStack {
249-
stack: VecDeque<i32>
249+
stack: VecDeque<i32>,
250250
}
251251

252-
253252
/**
254253
* `&self` means the method takes an immutable reference.
255254
* If you need a mutable reference, change it to `&mut self` instead.
256255
*/
257256
impl SortedStack {
258-
259257
fn new() -> Self {
260258
Self { stack: VecDeque::new() }
261259
}
@@ -281,9 +279,7 @@ impl SortedStack {
281279
fn is_empty(&self) -> bool {
282280
self.stack.is_empty()
283281
}
284-
}
285-
286-
/**
282+
}/**
287283
* Your SortedStack object will be instantiated and called as such:
288284
* let obj = SortedStack::new();
289285
* obj.push(val);

lcci/03.05.Sort of Stacks/README_EN.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,14 @@ func (s *SortedStack) IsEmpty() bool {
251251
```rust
252252
use std::collections::VecDeque;
253253
struct SortedStack {
254-
stack: VecDeque<i32>
254+
stack: VecDeque<i32>,
255255
}
256256

257-
258257
/**
259258
* `&self` means the method takes an immutable reference.
260259
* If you need a mutable reference, change it to `&mut self` instead.
261260
*/
262261
impl SortedStack {
263-
264262
fn new() -> Self {
265263
Self { stack: VecDeque::new() }
266264
}
@@ -286,9 +284,7 @@ impl SortedStack {
286284
fn is_empty(&self) -> bool {
287285
self.stack.is_empty()
288286
}
289-
}
290-
291-
/**
287+
}/**
292288
* Your SortedStack object will be instantiated and called as such:
293289
* let obj = SortedStack::new();
294290
* obj.push(val);

lcci/03.05.Sort of Stacks/Solution.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use std::collections::VecDeque;
22
struct SortedStack {
3-
stack: VecDeque<i32>
3+
stack: VecDeque<i32>,
44
}
55

6-
76
/**
87
* `&self` means the method takes an immutable reference.
98
* If you need a mutable reference, change it to `&mut self` instead.
109
*/
1110
impl SortedStack {
12-
1311
fn new() -> Self {
1412
Self { stack: VecDeque::new() }
1513
}
@@ -35,13 +33,11 @@ impl SortedStack {
3533
fn is_empty(&self) -> bool {
3634
self.stack.is_empty()
3735
}
38-
}
39-
40-
/**
36+
}/**
4137
* Your SortedStack object will be instantiated and called as such:
4238
* let obj = SortedStack::new();
4339
* obj.push(val);
4440
* obj.pop();
4541
* let ret_3: i32 = obj.peek();
4642
* let ret_4: bool = obj.is_empty();
47-
*/
43+
*/

0 commit comments

Comments
 (0)