Skip to content

Commit 9bca1a6

Browse files
author
ynn
committed
refactor: removes unnecessary parens
1 parent ce32e62 commit 9bca1a6

File tree

8 files changed

+115
-115
lines changed

8 files changed

+115
-115
lines changed

src/cc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub enum CC {
66

77
impl CC {
88
pub fn flip(&self) -> Self {
9-
match (self) {
9+
match self {
1010
CC::Left => CC::Right,
1111
CC::Right => CC::Left,
1212
}

src/codel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum Codel {
3131

3232
impl Display for Codel {
3333
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34-
let (r, g, b) = match (self) {
34+
let (r, g, b) = match self {
3535
Codel::LightRed => (255, 192, 192),
3636
Codel::LightYellow => (255, 255, 192),
3737
Codel::LightGreen => (192, 255, 192),
@@ -63,7 +63,7 @@ impl Display for Codel {
6363

6464
impl Codel {
6565
pub fn new(p: &Pixel) -> Option<Self> {
66-
match (p) {
66+
match p {
6767
#[rustfmt::skip]
6868
Pixel { r: 255, g: 192, b: 192 } => Some(Codel::LightRed),
6969
#[rustfmt::skip]
@@ -121,7 +121,7 @@ impl Codel {
121121
}
122122

123123
fn get_hue(&self) -> usize {
124-
match (self) {
124+
match self {
125125
Codel::LightRed | Codel::Red | Codel::DarkRed => 0,
126126
Codel::LightYellow | Codel::Yellow | Codel::DarkYellow => 1,
127127
Codel::LightGreen | Codel::Green | Codel::DarkGreen => 2,
@@ -133,7 +133,7 @@ impl Codel {
133133
}
134134

135135
fn get_lightness(&self) -> usize {
136-
match (self) {
136+
match self {
137137
Codel::LightRed
138138
| Codel::LightYellow
139139
| Codel::LightGreen
@@ -159,7 +159,7 @@ impl Codel {
159159
pub fn get_hue_difference(from: &Codel, to: &Codel) -> usize {
160160
let from = from.get_hue();
161161
let to = to.get_hue();
162-
if (to >= from) {
162+
if to >= from {
163163
to - from
164164
} else {
165165
to + 6 - from
@@ -169,7 +169,7 @@ impl Codel {
169169
pub fn get_lightness_difference(from: &Codel, to: &Codel) -> usize {
170170
let from = from.get_lightness();
171171
let to = to.get_lightness();
172-
if (to >= from) {
172+
if to >= from {
173173
to - from
174174
} else {
175175
to + 3 - from

src/command.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,114 +62,114 @@ impl Command {
6262
pub fn apply(&self, ip: &mut Interpreter, value: isize) -> Result<(), Box<dyn Error>> {
6363
assert!(value > 0);
6464
let stack = &mut ip.stack;
65-
match (self) {
65+
match self {
6666
Command::Push => {
6767
stack.push(value);
6868
}
6969
Command::Pop => {
7070
stack.pop();
7171
}
7272
Command::Add => {
73-
if (stack.len() >= 2) {
73+
if stack.len() >= 2 {
7474
let x = stack.pop().unwrap();
7575
let y = stack.pop().unwrap();
7676
stack.push(x + y);
7777
}
7878
}
7979
Command::Subtract => {
80-
if (stack.len() >= 2) {
80+
if stack.len() >= 2 {
8181
let x = stack.pop().unwrap();
8282
let y = stack.pop().unwrap();
8383
stack.push(y - x);
8484
}
8585
}
8686
Command::Multiply => {
87-
if (stack.len() >= 2) {
87+
if stack.len() >= 2 {
8888
let x = stack.pop().unwrap();
8989
let y = stack.pop().unwrap();
9090
stack.push(x * y);
9191
}
9292
}
9393
Command::Divide => {
94-
if (stack.len() >= 2) {
94+
if stack.len() >= 2 {
9595
let x = stack.pop().unwrap();
9696
let y = stack.pop().unwrap();
97-
if (x == 0) {
97+
if x == 0 {
9898
return Err(format!("zero-division at {:?}", value).into());
9999
}
100100
stack.push(y / x);
101101
}
102102
}
103103
Command::Mod => {
104-
if (stack.len() >= 2) {
104+
if stack.len() >= 2 {
105105
let x = stack.pop().unwrap();
106106
let y = stack.pop().unwrap();
107-
if (x == 0) {
107+
if x == 0 {
108108
return Err(format!("zero-division at {:?}", value).into());
109109
}
110110
#[allow(unstable_name_collisions)]
111111
stack.push(y - (y.div_floor(&x) * x)); //Python-style mod
112112
}
113113
}
114114
Command::Not => {
115-
if (!stack.is_empty()) {
115+
if !stack.is_empty() {
116116
let x = stack.pop().unwrap();
117-
if (x == 0) {
117+
if x == 0 {
118118
stack.push(1);
119119
} else {
120120
stack.push(0);
121121
}
122122
}
123123
}
124124
Command::Greater => {
125-
if (stack.len() >= 2) {
125+
if stack.len() >= 2 {
126126
let x = stack.pop().unwrap();
127127
let y = stack.pop().unwrap();
128-
if (y > x) {
128+
if y > x {
129129
stack.push(1);
130130
} else {
131131
stack.push(0);
132132
}
133133
}
134134
}
135135
Command::Pointer => {
136-
if (!stack.is_empty()) {
136+
if !stack.is_empty() {
137137
let x = stack.pop().unwrap();
138138
ip.dp = ip.dp.rotate_by(x);
139139
}
140140
}
141141
Command::Switch => {
142-
if (!stack.is_empty()) {
142+
if !stack.is_empty() {
143143
let x = stack.pop().unwrap();
144-
if (x.abs() % 2 == 1) {
144+
if x.abs() % 2 == 1 {
145145
ip.cc = ip.cc.flip();
146146
}
147147
}
148148
}
149149
Command::Duplicate => {
150-
if (!stack.is_empty()) {
150+
if !stack.is_empty() {
151151
stack.push(*stack.last().unwrap());
152152
}
153153
}
154154
Command::Roll => {
155-
if (stack.len() >= 2) {
155+
if stack.len() >= 2 {
156156
let num_roll = stack[stack.len() - 1];
157157
let depth = stack[stack.len() - 2];
158158
//if operation cannoe be done
159-
if ((depth < 0) || (stack.len() - 2 < depth as usize)) {
159+
if (depth < 0) || (stack.len() - 2 < depth as usize) {
160160
return Ok(());
161161
}
162162
for _ in 0..2 {
163163
stack.pop().unwrap();
164164
}
165165
//if operation can be done but virtually nothing happens
166-
if ((depth <= 1) || (num_roll == 0)) {
166+
if (depth <= 1) || (num_roll == 0) {
167167
return Ok(());
168168
}
169169

170170
//rotates the indices `[0, 1, 2, ..., depth - 1]`
171171
let mut position = VecDeque::from_iter(0..(depth as usize));
172-
if (num_roll > 0) {
172+
if num_roll > 0 {
173173
position.rotate_right((num_roll % depth) as usize);
174174
} else {
175175
position.rotate_left((num_roll.abs() % depth) as usize);
@@ -187,28 +187,28 @@ impl Command {
187187
}
188188
Command::ReadNumber => {
189189
let n = ip.stdin.read_integer();
190-
if (n.is_none()) {
190+
if n.is_none() {
191191
return Ok(());
192192
}
193193
stack.push(n.unwrap());
194194
}
195195
Command::ReadChar => {
196196
let c = ip.stdin.read_char();
197-
if (c.is_none()) {
197+
if c.is_none() {
198198
return Ok(());
199199
}
200200
stack.push(c.unwrap() as isize);
201201
}
202202
Command::WriteNumber => {
203-
if (!stack.is_empty()) {
203+
if !stack.is_empty() {
204204
let x = stack.pop().unwrap();
205205
ip.output(&format!("{}\n", x));
206206
}
207207
}
208208
Command::WriteChar => {
209-
if (!stack.is_empty()) {
209+
if !stack.is_empty() {
210210
let x = *stack.last().unwrap();
211-
if ((0 <= x) && (x <= char::MAX as isize)) {
211+
if (0 <= x) && (x <= char::MAX as isize) {
212212
stack.pop().unwrap();
213213
ip.output(&format!("{}", char::from_u32(x as u32).unwrap()));
214214
}

src/dp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ impl DP {
1515

1616
pub fn rotate_by(&self, i: isize) -> Self {
1717
let i = (*self as isize) + i;
18-
if (i >= 0) {
18+
if i >= 0 {
1919
Self::from_isize(i % 4).unwrap()
2020
} else {
2121
Self::from_isize((i % 4 + 4) % 4).unwrap()
2222
}
2323
}
2424

2525
pub fn get_displacement(&self) -> (isize, isize) {
26-
match (self) {
26+
match self {
2727
Self::Right => (0, 1),
2828
Self::Down => (1, 0),
2929
Self::Left => (0, -1),
@@ -34,15 +34,15 @@ impl DP {
3434

3535
impl FromPrimitive for DP {
3636
fn from_i64(i: i64) -> Option<Self> {
37-
if (i < 0) {
37+
if i < 0 {
3838
None
3939
} else {
4040
Self::from_u64(i as u64)
4141
}
4242
}
4343

4444
fn from_u64(i: u64) -> Option<Self> {
45-
match (i) {
45+
match i {
4646
0 => Some(DP::Right),
4747
1 => Some(DP::Down),
4848
2 => Some(DP::Left),

src/image.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Display for Image {
4848
(0..self.width)
4949
.map(|e| format!(
5050
"{:2}",
51-
if (e % 10 == 0) {
51+
if e % 10 == 0 {
5252
(e / 10).to_string()
5353
} else {
5454
" ".to_string()
@@ -104,7 +104,7 @@ impl Image {
104104
}
105105

106106
let codel_size = if let Some(codel_size) = codel_size {
107-
if (!Self::check_if_codel_size_is_valid(&pixels, codel_size)) {
107+
if !Self::check_if_codel_size_is_valid(&pixels, codel_size) {
108108
return Err("incorrect codel size is specified".into());
109109
}
110110
codel_size
@@ -155,7 +155,7 @@ impl Image {
155155
let p = &m[origin_y][origin_x];
156156
for x in 0..codel_size {
157157
for y in 0..codel_size {
158-
if (&m[origin_y + y][origin_x + x] != p) {
158+
if &m[origin_y + y][origin_x + x] != p {
159159
return false;
160160
}
161161
}
@@ -173,7 +173,7 @@ impl Image {
173173
if !((width % codel_size == 0) && (height % codel_size == 0)) {
174174
continue;
175175
}
176-
if (Self::check_if_codel_size_is_valid(m, codel_size)) {
176+
if Self::check_if_codel_size_is_valid(m, codel_size) {
177177
return Some(codel_size);
178178
}
179179
}
@@ -185,7 +185,7 @@ impl Image {
185185
let mut visited = HashSet::new();
186186
for i in 0..m.len() {
187187
for j in 0..m[0].len() {
188-
if (visited.contains(&(i, j))) {
188+
if visited.contains(&(i, j)) {
189189
continue;
190190
}
191191
let visited_local = Self::dfs((i, j), &m[i][j], m);
@@ -209,16 +209,16 @@ impl Image {
209209

210210
fn four_adjacents((i, j): (usize, usize), height: usize, width: usize) -> Vec<(usize, usize)> {
211211
let mut ret = vec![];
212-
if (i != 0) {
212+
if i != 0 {
213213
ret.push((i - 1, j));
214214
}
215-
if (i != height - 1) {
215+
if i != height - 1 {
216216
ret.push((i + 1, j));
217217
}
218-
if (j != 0) {
218+
if j != 0 {
219219
ret.push((i, j - 1));
220220
}
221-
if (j != width - 1) {
221+
if j != width - 1 {
222222
ret.push((i, j + 1));
223223
}
224224
ret
@@ -273,10 +273,10 @@ impl Image {
273273
origin.0 as isize + displacement.0,
274274
origin.1 as isize + displacement.1,
275275
);
276-
if ((0 <= next.0)
276+
if (0 <= next.0)
277277
&& (next.0 < self.height as isize)
278278
&& (0 <= next.1)
279-
&& (next.1 < self.width as isize))
279+
&& (next.1 < self.width as isize)
280280
{
281281
Some((next.0 as usize, next.1 as usize))
282282
} else {

0 commit comments

Comments
 (0)