basic/crate-module/use #646
Replies: 23 comments 20 replies
-
这里内容不够全。建议介绍不同目录的代码文件的引用,即代码文件分布在不同目录时,怎样使用。 |
Beta Was this translation helpful? Give feedback.
-
怎么在我的项目里用这个restaurant呢.. |
Beta Was this translation helpful? Give feedback.
-
不知道后边有没有分享真实项目package, crate, module的使用的,因为这里不仅是规则上的问题,更多的是一种最佳实践。 |
Beta Was this translation helpful? Give feedback.
-
讲得非常清楚,看懂了,太棒了 |
Beta Was this translation helpful? Give feedback.
-
还是要用起来才知道 |
Beta Was this translation helpful? Give feedback.
-
这个文件夹的问题还是要实践 |
Beta Was this translation helpful? Give feedback.
-
引入项再导出---的pub use没看懂,在另一个文件中引入mod之后pub use照样不能访问其中的非pub模块都嘛?请高手赐教 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
我没看明白受限的可见性那块的描述。代码上给点注释啊。 |
Beta Was this translation helpful? Give feedback.
-
// lib.rs
pub mod a {
}
// main.rs
//
use test::a;
fn main() {}
[package]
name = "test"
version = "0.1.0"
edition = "2021" 这样写可以通过cargo编译,但是VS Code报错提示:
我有些疑惑默认lib.rs和main.rs中模块的关系 |
Beta Was this translation helpful? Give feedback.
-
https://www.cnblogs.com/fire-cat/p/17578600.html |
Beta Was this translation helpful? Give feedback.
-
总结:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
2.12 竟然是我看的最懵逼的一章,莫非是我心态轻浮了。。。 |
Beta Was this translation helpful? Give feedback.
-
受限的可见性这里举的例子不太合适 // 目标:`a` 导出 `I`、`bar` and `foo`,其他的不导出
pub mod a {
pub const I: i32 = 3;
fn semisecret(x: i32) -> i32 {
use self::b::c::J;
x + J
}
pub fn bar(z: i32) -> i32 {
semisecret(I) * z
}
pub fn foo(y: i32) -> i32 {
semisecret(I) + y
}
mod b {
mod c {
const J: i32 = 4;
}
}
} 这里本身函数 // 目标:`a` 导出 `I`、`bar` and `foo`,其他的不导出
pub mod a {
pub const I: i32 = 3;
fn semisecret(x: i32) -> i32 {
use self::b::c::J;
x + J
}
pub fn bar(z: i32) -> i32 {
semisecret(I) * z
}
pub fn foo(y: i32) -> i32 {
semisecret(I) + y
}
mod b {
pub mod c {
pub const J: i32 = 4;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
怎么用lib.rs查找包啊,没看懂 |
Beta Was this translation helpful? Give feedback.
-
模块mod这块不太复杂,但可见性这块挺复杂的,结合实战继续学习吧! |
Beta Was this translation helpful? Give feedback.
-
二刷,觉得更加牛逼了 |
Beta Was this translation helpful? Give feedback.
-
basic/crate-module/use
https://course.rs/basic/crate-module/use.html
Beta Was this translation helpful? Give feedback.
All reactions