mirror of
https://github.com/Dhghomon/easy_rust
synced 2024-11-19 15:25:37 +00:00
deploy: f2efc00ea6
This commit is contained in:
parent
cdd057c9f3
commit
b391d67b32
@ -218,7 +218,9 @@ fn main() {
|
||||
);
|
||||
}
|
||||
</code></pre></pre>
|
||||
<p>The message is: "thread 'main' panicked at 'called <code>Option::unwrap()</code> on a <code>None</code> value', src\main.rs:14:9".</p>
|
||||
<p>The message is:</p>
|
||||
<pre><code class="language-text">thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src\main.rs:14:9
|
||||
</code></pre>
|
||||
<p>But we don't need to use <code>.unwrap()</code>. We can use a <code>match</code>. Then we can print the value we have <code>Some</code>, and not touch it if we have <code>None</code>. For example:</p>
|
||||
<pre><pre class="playground"><code class="language-rust">fn take_fifth(value: Vec<i32>) -> Option<i32> {
|
||||
if value.len() < 4 {
|
||||
|
@ -2919,7 +2919,9 @@ fn main() {
|
||||
);
|
||||
}
|
||||
</code></pre></pre>
|
||||
<p>The message is: "thread 'main' panicked at 'called <code>Option::unwrap()</code> on a <code>None</code> value', src\main.rs:14:9".</p>
|
||||
<p>The message is:</p>
|
||||
<pre><code class="language-text">thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src\main.rs:14:9
|
||||
</code></pre>
|
||||
<p>But we don't need to use <code>.unwrap()</code>. We can use a <code>match</code>. Then we can print the value we have <code>Some</code>, and not touch it if we have <code>None</code>. For example:</p>
|
||||
<pre><pre class="playground"><code class="language-rust">fn take_fifth(value: Vec<i32>) -> Option<i32> {
|
||||
if value.len() < 4 {
|
||||
|
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