随笔分类 - Rust
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/std/box.html 示例 默认情况下,rust 一般都是在栈上进行内存分配,如果想在堆上分配内存,需要使用 Box<T>。 m
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/iter_result.html 示例 整个迭代失败 fn main() { let strings = vec!["tofu", "
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/iter_result.html 示例 包含错误值 fn main() { let strings = vec!["tofu", "9
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/wrap_error.html 示例 main.rs use std::error; use
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/reenter_question_mark.html 示例 main.rs use std:
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html 示例 main.rs use std::error;
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/define_error_type.html 示例 main.rs type Result<
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/option_result.html 示例 返回 Option use std
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/multiple_error_types.html 示例 main.rs fn double_first(vec: Vec<&str>
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/result/enter_question_mark.html 示例 如果想得到值而不产生恐慌,有一种简单的方式,那就是使用问号。 m
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/result/early_returns.html 示例 main.rs use std::num::ParseIntError; f
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/result/result_alias.html 示例 main.rs use std::num::ParseIntError; //
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/result/result_map.html 示例 Result 的 map 方法可以对值进行转换。 繁琐版本 use std::nu
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/result.html 示例 Result 和 Option 有点类似,不过它代表可能失败,而不是可能不存在。 恐慌 fn multi
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/option_unwrap/and_then.html 示例 main.rs #![allow(dead_code)] #[deriv
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/option_unwrap/map.html 示例 Option 有个 map 方法,可以进行值的映射,或者说转换。 main.rs
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/option_unwrap/question_mark.html 示例 使用问号进行展开,具有更好的可读性。 main.rs stru
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/option_unwrap.html 示例 除了使用恐慌,还可以使用可选(Option)来处理一些意外情况。 main.rs fn g
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/error/panic.html 示例 恐慌(panic)和其它语言中的异常和错误类似,一般针对不可处理的错误。如果没有经过处理,就会直接退出程序
阅读全文
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/macros/variadics.html 示例 main.rs macro_rules! calculate { (eval $e:expr)
阅读全文