Rust - 如何从 src 文件夹中调用函数到示例文件夹中的代码?
如果我在 src/test.rs
中有这个函数,
pub fn print_something(){
println!("Something");
}
我如何在 example/test.rs
中调用它?
我尝试过 extern crate
、mod
、use
但这些都不起作用。
If I have this function in src/test.rs
pub fn print_something(){
println!("Something");
}
how can I call it in the example/test.rs
?
I've tried with extern crate
, mod
, use
but none of these worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您必须在 src/lib.rs 中声明
test
模块:然后,在 Examples/test.rs 中,将其用作库:
First, you have to declare the
test
module in src/lib.rs:Then, inside examples/test.rs, just use it as a library: