<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>04-结果 `Result` on 编程那些事儿</title><link>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/</link><description>Recent content in 04-结果 `Result` on 编程那些事儿</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Fri, 21 Aug 2026 22:34:20 +0800</lastBuildDate><atom:link href="https://before80.github.io/prgms/Rust/RustByExample/error/04-result/index.xml" rel="self" type="application/rss+xml"/><item><title>01-`Result` 的 `map`</title><link>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/01-result-map/</link><pubDate>Thu, 20 Aug 2026 21:20:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/01-result-map/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/"&gt;Rust By Example&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/error/result/result_map.html"&gt;https://doc.rust-lang.org/stable/rust-by-example/error/result/result_map.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="result-的-map"&gt;&lt;code&gt;Result&lt;/code&gt; 的 &lt;code&gt;map&lt;/code&gt;&lt;/h1&gt;
&lt;p&gt;上一节的 &lt;code&gt;multiply&lt;/code&gt; 函数的 panic 设计不是健壮的（robust）。一般地，我们希望把错误返回给调用者，这样它可以决定回应错误的正确方式。&lt;/p&gt;</description></item><item><title>02-给 `Result` 取别名</title><link>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/02-result-alias/</link><pubDate>Thu, 20 Aug 2026 21:20:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/02-result-alias/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/"&gt;Rust By Example&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/error/result/result_alias.html"&gt;https://doc.rust-lang.org/stable/rust-by-example/error/result/result_alias.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="给-result-取别名"&gt;给 &lt;code&gt;Result&lt;/code&gt; 取别名&lt;/h1&gt;
&lt;p&gt;当我们要重用某个 &lt;code&gt;Result&lt;/code&gt; 类型时，该怎么办呢？回忆一下，Rust 允许我们创建&lt;a href="../../types/04-alias/"&gt;别名&lt;/a&gt;。若某个 &lt;code&gt;Result&lt;/code&gt; 有可能被重用，我们可以方便地给它取一个别名。&lt;/p&gt;</description></item><item><title>03-提前返回</title><link>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/03-early-returns/</link><pubDate>Thu, 20 Aug 2026 21:20:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/03-early-returns/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/"&gt;Rust By Example&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/error/result/early_returns.html"&gt;https://doc.rust-lang.org/stable/rust-by-example/error/result/early_returns.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="提前返回"&gt;提前返回&lt;/h1&gt;
&lt;p&gt;在上一个例子中，我们显式地使用组合算子处理了错误。另一种处理错误的方式是使用
&lt;code&gt;match&lt;/code&gt; 语句和&lt;strong&gt;提前返回&lt;/strong&gt;（early return）的结合。&lt;/p&gt;</description></item><item><title>04-引入 `?`</title><link>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/04-enter-question-mark/</link><pubDate>Thu, 20 Aug 2026 21:20:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/RustByExample/error/04-result/04-enter-question-mark/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/"&gt;Rust By Example&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://doc.rust-lang.org/stable/rust-by-example/error/result/enter_question_mark.html"&gt;https://doc.rust-lang.org/stable/rust-by-example/error/result/enter_question_mark.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="引入-"&gt;引入 &lt;code&gt;?&lt;/code&gt;&lt;/h1&gt;
&lt;p&gt;有时我们只是想 &lt;code&gt;unwrap&lt;/code&gt; 且避免产生 &lt;code&gt;panic&lt;/code&gt;。到现在为止，对 &lt;code&gt;unwrap&lt;/code&gt; 的错误处理都在强迫我们一层层地嵌套，然而我们只是想把里面的变量拿出来。&lt;code&gt;?&lt;/code&gt; 正是为这种情况准备的。&lt;/p&gt;</description></item></channel></rss>