Rust 程序设计语言 简体中文版 1.85.0内的任意地方,通过代码路径引用该模块的代码。举例而言,一个 garden vegetables 模块下的 Asparagus 类型可以通过 crate::garden::vegetables::Asparagus 访 问。 • 私有 vs 公用: 一个模块里的代码默认对其父模块私有。为了使一个模块公用,应当在声明时 使用 pub mod 替代 mod。为了使一个公用模块内部的成员公用,应当在声明前使用pub。 • use 关键字: `target/debug/error-handling` thread 'main' panicked at src/main.rs:8:23: Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" } note: run with `RUST_BACKTRACE=1` environment 调用 panic! 时提供的 错误信息: thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:4:49 同样,expect 方法也允许我们自定义0 码力 | 562 页 | 3.23 MB | 26 天前3
共 1 条
- 1













