Skip to content

feat: add rustfmt tool #3139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Run prettier
run: |
git config --global core.quotepath off
changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.js$|\.ts$|\.php$|\.sql$|\.rs$|\.md$' || true)
changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.js$|\.ts$|\.php$|\.sql$|\.md$' || true)
if [ -n "$changed_files" ]; then
echo "Running prettier on the changed files"
echo "$changed_files" | xargs -d '\n' npx prettier --write
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"options": { "parser": "mysql" }
}
],
"plugins": ["prettier-plugin-rust", "prettier-plugin-sql-cst", "@prettier/plugin-php"]
"plugins": ["prettier-plugin-sql-cst", "@prettier/plugin-php"]
}
10 changes: 2 additions & 8 deletions basic/sorting/HeapSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,13 @@ fn sink(nums: &mut Vec<i32>, mut i: usize, n: usize) {
fn main() -> io::Result<()> {
let mut s = String::new();
io::stdin().read_line(&mut s)?;
let s: Vec<usize> = s
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let s: Vec<usize> = s.split(' ').map(|s| s.trim().parse().unwrap()).collect();
// let n = s[0];
let m = s[1];

let mut nums = String::new();
io::stdin().read_line(&mut nums)?;
let mut nums: Vec<i32> = nums
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();

heap_sort(&mut nums);
for num in nums.iter().take(m) {
Expand Down
10 changes: 2 additions & 8 deletions basic/sorting/HeapSort/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@ fn sink(nums: &mut Vec<i32>, mut i: usize, n: usize) {
fn main() -> io::Result<()> {
let mut s = String::new();
io::stdin().read_line(&mut s)?;
let s: Vec<usize> = s
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let s: Vec<usize> = s.split(' ').map(|s| s.trim().parse().unwrap()).collect();
// let n = s[0];
let m = s[1];

let mut nums = String::new();
io::stdin().read_line(&mut nums)?;
let mut nums: Vec<i32> = nums
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();

heap_sort(&mut nums);
for num in nums.iter().take(m) {
Expand Down
5 changes: 1 addition & 4 deletions basic/sorting/MergeSort/Main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ fn main() -> io::Result<()> {

let mut nums = String::new();
io::stdin().read_line(&mut nums)?;
let mut nums: Vec<i32> = nums
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();

merge_sort(&mut nums, 0, n - 1);
for num in nums.iter() {
Expand Down
5 changes: 1 addition & 4 deletions basic/sorting/MergeSort/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ fn main() -> io::Result<()> {

let mut nums = String::new();
io::stdin().read_line(&mut nums)?;
let mut nums: Vec<i32> = nums
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();

merge_sort(&mut nums, 0, n - 1);
for num in nums.iter() {
Expand Down
5 changes: 1 addition & 4 deletions basic/sorting/QuickSort/Main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ fn main() -> io::Result<()> {

let mut nums = String::new();
io::stdin().read_line(&mut nums)?;
let mut nums: Vec<i32> = nums
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();

quick_sort(&mut nums, 0, n - 1);
for num in nums.iter() {
Expand Down
5 changes: 1 addition & 4 deletions basic/sorting/QuickSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ fn main() -> io::Result<()> {

let mut nums = String::new();
io::stdin().read_line(&mut nums)?;
let mut nums: Vec<i32> = nums
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();

quick_sort(&mut nums, 0, n - 1);
for num in nums.iter() {
Expand Down
5 changes: 1 addition & 4 deletions basic/sorting/QuickSort/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ fn main() -> io::Result<()> {

let mut nums = String::new();
io::stdin().read_line(&mut nums)?;
let mut nums: Vec<i32> = nums
.split(' ')
.map(|s| s.trim().parse().unwrap())
.collect();
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();

quick_sort(&mut nums, 0, n - 1);
for num in nums.iter() {
Expand Down
6 changes: 5 additions & 1 deletion lcci/01.03.String to URL/Solution2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ impl Solution {
s.chars()
.take(length as usize)
.map(|c| {
if c == ' ' { "%20".to_string() } else { c.to_string() }
if c == ' ' {
"%20".to_string()
} else {
c.to_string()
}
})
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion lcci/02.05.Sum Lists/Solution.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
impl Solution {
pub fn add_two_numbers(
mut l1: Option<Box<ListNode>>,
mut l2: Option<Box<ListNode>>
mut l2: Option<Box<ListNode>>,
) -> Option<Box<ListNode>> {
let mut dummy = Some(Box::new(ListNode::new(0)));
let mut cur = dummy.as_mut();
Expand Down
9 changes: 1 addition & 8 deletions lcci/03.02.Min Stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,7 @@ impl MinStack {
fn get_min(&self) -> i32 {
*self.min_stack.back().unwrap()
}
}/**
* Your MinStack object will be instantiated and called as such:
* let obj = MinStack::new();
* obj.push(x);
* obj.pop();
* let ret_3: i32 = obj.top();
* let ret_4: i32 = obj.get_min();
*/
}
```

#### C#
Expand Down
9 changes: 1 addition & 8 deletions lcci/03.02.Min Stack/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,7 @@ impl MinStack {
fn get_min(&self) -> i32 {
*self.min_stack.back().unwrap()
}
}/**
* Your MinStack object will be instantiated and called as such:
* let obj = MinStack::new();
* obj.push(x);
* obj.pop();
* let ret_3: i32 = obj.top();
* let ret_4: i32 = obj.get_min();
*/
}
```

#### C#
Expand Down
14 changes: 5 additions & 9 deletions lcci/03.02.Min Stack/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ struct MinStack {
impl MinStack {
/** initialize your data structure here. */
fn new() -> Self {
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
Self {
stack: VecDeque::new(),
min_stack: VecDeque::new(),
}
}

fn push(&mut self, x: i32) {
Expand All @@ -35,11 +38,4 @@ impl MinStack {
fn get_min(&self) -> i32 {
*self.min_stack.back().unwrap()
}
}/**
* Your MinStack object will be instantiated and called as such:
* let obj = MinStack::new();
* obj.push(x);
* obj.pop();
* let ret_3: i32 = obj.top();
* let ret_4: i32 = obj.get_min();
*/
}
9 changes: 1 addition & 8 deletions lcci/03.04.Implement Queue using Stacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,7 @@ impl MyQueue {
}
}
}
}/**
* Your MyQueue object will be instantiated and called as such:
* let obj = MyQueue::new();
* obj.push(x);
* let ret_2: i32 = obj.pop();
* let ret_3: i32 = obj.peek();
* let ret_4: bool = obj.empty();
*/
}
```

#### Swift
Expand Down
9 changes: 1 addition & 8 deletions lcci/03.04.Implement Queue using Stacks/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,7 @@ impl MyQueue {
}
}
}
}/**
* Your MyQueue object will be instantiated and called as such:
* let obj = MyQueue::new();
* obj.push(x);
* let ret_2: i32 = obj.pop();
* let ret_3: i32 = obj.peek();
* let ret_4: bool = obj.empty();
*/
}
```

#### Swift
Expand Down
9 changes: 1 addition & 8 deletions lcci/03.04.Implement Queue using Stacks/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,4 @@ impl MyQueue {
}
}
}
}/**
* Your MyQueue object will be instantiated and called as such:
* let obj = MyQueue::new();
* obj.push(x);
* let ret_2: i32 = obj.pop();
* let ret_3: i32 = obj.peek();
* let ret_4: bool = obj.empty();
*/
}
9 changes: 1 addition & 8 deletions lcci/03.05.Sort of Stacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,7 @@ impl SortedStack {
fn is_empty(&self) -> bool {
self.stk.is_empty()
}
}/**
* Your SortedStack object will be instantiated and called as such:
* let obj = SortedStack::new();
* obj.push(val);
* obj.pop();
* let ret_3: i32 = obj.peek();
* let ret_4: bool = obj.is_empty();
*/
}
```

#### Swift
Expand Down
9 changes: 1 addition & 8 deletions lcci/03.05.Sort of Stacks/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,7 @@ impl SortedStack {
fn is_empty(&self) -> bool {
self.stk.is_empty()
}
}/**
* Your SortedStack object will be instantiated and called as such:
* let obj = SortedStack::new();
* obj.push(val);
* obj.pop();
* let ret_3: i32 = obj.peek();
* let ret_4: bool = obj.is_empty();
*/
}
```

#### Swift
Expand Down
15 changes: 6 additions & 9 deletions lcci/03.05.Sort of Stacks/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ impl SortedStack {
}

fn peek(&self) -> i32 {
if self.is_empty() { -1 } else { *self.stk.back().unwrap() }
if self.is_empty() {
-1
} else {
*self.stk.back().unwrap()
}
}

fn is_empty(&self) -> bool {
self.stk.is_empty()
}
}/**
* Your SortedStack object will be instantiated and called as such:
* let obj = SortedStack::new();
* obj.push(val);
* obj.pop();
* let ret_3: i32 = obj.peek();
* let ret_4: bool = obj.is_empty();
*/
}
9 changes: 1 addition & 8 deletions lcci/03.06.Animal Shelter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,7 @@ impl AnimalShelf {
vec![cat, 0]
}
}
}/**
* Your AnimalShelf object will be instantiated and called as such:
* let obj = AnimalShelf::new();
* obj.enqueue(animal);
* let ret_2: Vec<i32> = obj.dequeue_any();
* let ret_3: Vec<i32> = obj.dequeue_dog();
* let ret_4: Vec<i32> = obj.dequeue_cat();
*/
}
```

#### Swift
Expand Down
9 changes: 1 addition & 8 deletions lcci/03.06.Animal Shelter/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,7 @@ impl AnimalShelf {
vec![cat, 0]
}
}
}/**
* Your AnimalShelf object will be instantiated and called as such:
* let obj = AnimalShelf::new();
* obj.enqueue(animal);
* let ret_2: Vec<i32> = obj.dequeue_any();
* let ret_3: Vec<i32> = obj.dequeue_dog();
* let ret_4: Vec<i32> = obj.dequeue_cat();
*/
}
```

#### Swift
Expand Down
14 changes: 3 additions & 11 deletions lcci/03.06.Animal Shelter/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ impl AnimalShelf {
}

fn dequeue_any(&mut self) -> Vec<i32> {
if
self.q[0].is_empty() ||
(!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
if self.q[0].is_empty()
|| (!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
{
self.dequeue_dog()
} else {
Expand All @@ -43,11 +42,4 @@ impl AnimalShelf {
vec![cat, 0]
}
}
}/**
* Your AnimalShelf object will be instantiated and called as such:
* let obj = AnimalShelf::new();
* obj.enqueue(animal);
* let ret_2: Vec<i32> = obj.dequeue_any();
* let ret_3: Vec<i32> = obj.dequeue_dog();
* let ret_4: Vec<i32> = obj.dequeue_cat();
*/
}
16 changes: 6 additions & 10 deletions lcci/04.02.Minimum Height Tree/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,19 @@
// }
// }
// }
use std::rc::Rc;
use std::cell::RefCell;
use std::rc::Rc;
impl Solution {
fn dfs(nums: &Vec<i32>, l: usize, r: usize) -> Option<Rc<RefCell<TreeNode>>> {
if l >= r {
return None;
}
let mid = (l + r) >> 1;
Some(
Rc::new(
RefCell::new(TreeNode {
val: nums[mid],
left: Self::dfs(nums, l, mid),
right: Self::dfs(nums, mid + 1, r),
})
)
)
Some(Rc::new(RefCell::new(TreeNode {
val: nums[mid],
left: Self::dfs(nums, l, mid),
right: Self::dfs(nums, mid + 1, r),
})))
}
pub fn sorted_array_to_bst(nums: Vec<i32>) -> Option<Rc<RefCell<TreeNode>>> {
Self::dfs(&nums, 0, nums.len())
Expand Down
2 changes: 1 addition & 1 deletion lcci/04.03.List of Depth/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
// }
// }
// }
use std::rc::Rc;
use std::cell::RefCell;
use std::collections::VecDeque;
use std::rc::Rc;
impl Solution {
pub fn list_of_depth(tree: Option<Rc<RefCell<TreeNode>>>) -> Vec<Option<Box<ListNode>>> {
let mut res = vec![];
Expand Down
Loading
Loading