mirror of
https://github.com/Dhghomon/easy_rust
synced 2024-11-17 15:29:51 +00:00
deploy: 0992266d81
This commit is contained in:
parent
1c14a0b884
commit
84e32e4362
@ -496,7 +496,10 @@ fn math(input: &str) -> i32 {
|
||||
while let Some(entry) = math_iter.next() { // Iter through the items
|
||||
if entry.contains('-') { // If it has a - character, check if it's even or odd
|
||||
if entry.chars().count() % 2 == 1 {
|
||||
adds = false;
|
||||
adds = match adds {
|
||||
true => false,
|
||||
false => true
|
||||
};
|
||||
continue; // Go to the next item
|
||||
} else {
|
||||
continue;
|
||||
@ -585,7 +588,6 @@ warning: equality checks against true are unnecessary
|
||||
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
|
||||
</code></pre>
|
||||
<p>This is true: <code>for entry in math_iter</code> is much simpler than <code>while let Some(entry) = math_iter.next()</code>. And a <code>for</code> loop is actually an iterator so we don't have any reason to write <code>.iter()</code>. Thanks, clippy! And also we didn't need to make <code>math_iter</code>: we can just write <code>for entry in result_vec</code>.</p>
|
||||
<p>And the second point is true too: <code>if adds == true</code> can just be <code>if adds</code> (because <code>adds</code> = <code>true</code>).</p>
|
||||
<p>Now we'll start some real refactoring. Instead of separate variables, we will create a <code>Calculator</code> struct. This will have all the variables we used together. We will change two names to make it more clear. <code>result_vec</code> will become <code>results</code>, and <code>push_string</code> will become <code>current_input</code> (current means "now"). And so far it only has one method: new.</p>
|
||||
<pre><pre class="playground"><code class="language-rust">
|
||||
<span class="boring">#![allow(unused)]
|
||||
@ -677,7 +679,10 @@ fn math(input: &str) -> i32 {
|
||||
for entry in calculator.results {
|
||||
if entry.contains('-') {
|
||||
if entry.chars().count() % 2 == 1 {
|
||||
calculator.adds = false;
|
||||
adds = match adds {
|
||||
true => false,
|
||||
false => true
|
||||
};
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
@ -799,7 +804,10 @@ fn math(input: &str) -> i32 {
|
||||
for entry in calculator.results {
|
||||
if entry.contains('-') {
|
||||
if entry.chars().count() % 2 == 1 {
|
||||
calculator.adds = false;
|
||||
adds = match adds {
|
||||
true => false,
|
||||
false => true
|
||||
};
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
|
16
print.html
16
print.html
@ -9186,7 +9186,10 @@ fn math(input: &str) -> i32 {
|
||||
while let Some(entry) = math_iter.next() { // Iter through the items
|
||||
if entry.contains('-') { // If it has a - character, check if it's even or odd
|
||||
if entry.chars().count() % 2 == 1 {
|
||||
adds = false;
|
||||
adds = match adds {
|
||||
true => false,
|
||||
false => true
|
||||
};
|
||||
continue; // Go to the next item
|
||||
} else {
|
||||
continue;
|
||||
@ -9275,7 +9278,6 @@ warning: equality checks against true are unnecessary
|
||||
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
|
||||
</code></pre>
|
||||
<p>This is true: <code>for entry in math_iter</code> is much simpler than <code>while let Some(entry) = math_iter.next()</code>. And a <code>for</code> loop is actually an iterator so we don't have any reason to write <code>.iter()</code>. Thanks, clippy! And also we didn't need to make <code>math_iter</code>: we can just write <code>for entry in result_vec</code>.</p>
|
||||
<p>And the second point is true too: <code>if adds == true</code> can just be <code>if adds</code> (because <code>adds</code> = <code>true</code>).</p>
|
||||
<p>Now we'll start some real refactoring. Instead of separate variables, we will create a <code>Calculator</code> struct. This will have all the variables we used together. We will change two names to make it more clear. <code>result_vec</code> will become <code>results</code>, and <code>push_string</code> will become <code>current_input</code> (current means "now"). And so far it only has one method: new.</p>
|
||||
<pre><pre class="playground"><code class="language-rust">
|
||||
<span class="boring">#![allow(unused)]
|
||||
@ -9367,7 +9369,10 @@ fn math(input: &str) -> i32 {
|
||||
for entry in calculator.results {
|
||||
if entry.contains('-') {
|
||||
if entry.chars().count() % 2 == 1 {
|
||||
calculator.adds = false;
|
||||
adds = match adds {
|
||||
true => false,
|
||||
false => true
|
||||
};
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
@ -9489,7 +9494,10 @@ fn math(input: &str) -> i32 {
|
||||
for entry in calculator.results {
|
||||
if entry.contains('-') {
|
||||
if entry.chars().count() % 2 == 1 {
|
||||
calculator.adds = false;
|
||||
adds = match adds {
|
||||
true => false,
|
||||
false => true
|
||||
};
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user