eat_at_restaurant函数是我们 crate 库的一个公共 API,所以我们使用pub关键字来标记它。在href="https://api.ltpp.vip/Article/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#%E4%BD%BF%E7%94%A8-pub-%E5%85%B3%E9%94%AE%E5%AD%97%E6%9A%B4%E9%9C%B2%E8%B7%AF%E5%BE%84...
前面我们提到过src/main.rs和src/lib.rs被称为 crate 根。之所以这样命名,是因为这两个文件的任一个文件的内容都在 crate 的模块结构的根部,形成了一个名为 crate 的模块,该结构被称为模块树(module tree)。 本例的模块树结构: crate └── front_of_house ├── hosting │ ├── add_to_waitlist ...
可以通过在模块的mod.rs文件中添加以下代码来实现: // 文件:my_package/src/my_module/mod.rs pub mod my_module; 4. 在其他模块中使用模块 在其他模块中使用您创建的模块时,只需要将其导入即可。例如,假设您的项目中有一个名为main.rs的模块,并且您想在其中使用my_module,可以这样做: // 文件:my_packag...
用了很长一段时间nvim写rust,还没有用IDEA这样的IDE来写rust。就准备用一下,一用发现,还不太会在IDEA上用rust。 碰到的第一个问题就是 IDEA 提示: file is not included in module tree, analysis is not available fn main 也没有可以运行的按钮,但是命令行使用 cargo run 正常。这个说明应该是IDEA的配置...
很多人常犯的第一个错误是因为我们有像config.rs,health_route.rs这样的文件,所以我们就认为这些文件就是模块(module)且可以在其他的文件中将其导入。 下面是从我们的视角(文件系统树(file system tree))看到的内容和从编译器的角度(模块树(module tree))看到的内容: ...
module tree模块树,rust语言用于管理工程中模块的抽象结构。想要使用模块,那么该模块必须包含在模块树中(rust-analyzer插件的提示:file not included in module tree)。 当模块引出后,其他模块可以将其引入,我把这一状态称作挂载。 mod.rs ├─src │ │ file.rs ...
下面是从我们的视角(文件系统树(file system tree))看到的内容和从编译器的角度(模块树(module tree))看到的内容: 令人惊奇,编译器只看到了crate模块,也就是我们的main.rs文件。这是因为我们需要显式地在Rust中构建模块树——在文件系统树和模块树之间不存在隐式的转换。 我们需要显式地在Rust中构建模块树——...
Module(模块) Package Package 用于管理一个或多个Crate,创建一个Package的方式是使用cargo new stark命令: AI检测代码解析 [root@b0b5a9371ce4 stark]# tree . ├── Cargo.toml └── src └── main.rs 1 directory, 2 files 1. 2. 3. ...
可以看到这里不管用绝对路径还是相对路径都报错了,错误信息是模块hosting和函数add_to_waitlist是私有(private)的。我们先暂时放下这个错误,根据这里的错误提示,我们知道了当我们定义一个module时,默认情况下是私有的,我们可以通过这种方法来封装一些代码的实现细节。
File is not included in module tree, analysis is not availablefor every file in the project. I tried invalidating the cache and restarting etc. but that did not help. I figured out that the latest0.2version just before the jump0.3works and analyzes the files correctly. However, the0.2version...