简介
在本实验中,我们将学习 Rust 中的 ?
运算符,它允许我们通过返回 Err
而不是使程序恐慌(panic)来简化错误处理。我们还将探索 try!
宏,它在 ?
运算符引入之前实现了类似的功能。
注意:如果实验未指定文件名,你可以使用任何你想要的文件名。例如,你可以使用
main.rs
,通过rustc main.rs &&./main
来编译并运行它。
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
rust(("Rust")) -.-> rust/ErrorHandlingandDebuggingGroup(["Error Handling and Debugging"])
rust(("Rust")) -.-> rust/AdvancedTopicsGroup(["Advanced Topics"])
rust(("Rust")) -.-> rust/BasicConceptsGroup(["Basic Concepts"])
rust(("Rust")) -.-> rust/DataTypesGroup(["Data Types"])
rust(("Rust")) -.-> rust/FunctionsandClosuresGroup(["Functions and Closures"])
rust/BasicConceptsGroup -.-> rust/variable_declarations("Variable Declarations")
rust/DataTypesGroup -.-> rust/integer_types("Integer Types")
rust/DataTypesGroup -.-> rust/string_type("String Type")
rust/FunctionsandClosuresGroup -.-> rust/function_syntax("Function Syntax")
rust/FunctionsandClosuresGroup -.-> rust/expressions_statements("Expressions and Statements")
rust/ErrorHandlingandDebuggingGroup -.-> rust/error_propagation("Error Propagation")
rust/AdvancedTopicsGroup -.-> rust/operator_overloading("Traits for Operator Overloading")
subgraph Lab Skills
rust/variable_declarations -.-> lab-99243{{"使用问号进行 Rust 错误处理"}}
rust/integer_types -.-> lab-99243{{"使用问号进行 Rust 错误处理"}}
rust/string_type -.-> lab-99243{{"使用问号进行 Rust 错误处理"}}
rust/function_syntax -.-> lab-99243{{"使用问号进行 Rust 错误处理"}}
rust/expressions_statements -.-> lab-99243{{"使用问号进行 Rust 错误处理"}}
rust/error_propagation -.-> lab-99243{{"使用问号进行 Rust 错误处理"}}
rust/operator_overloading -.-> lab-99243{{"使用问号进行 Rust 错误处理"}}
end