使用命名空间而不是文件夹名称

Syn*_*ose 2 rust rust-cargo

说我有一个项目:

foo-bar
  | - lib.rs
  | - ....
Run Code Online (Sandbox Code Playgroud)

但我不想要命名空间foo-bar,我只想要bar. 无论如何要在中指定这个lib.rs?显而易见的解决方案是重命名foo-barbar,但在这种情况下我不能这样做。

sta*_*lue 5

您可以在 中指定库的名称Cargo.toml,请参阅Cargo 文档

[lib]
# The name of a target is the name of the library that will be generated. This
# is defaulted to the name of the package or project.
name = "foo"
Run Code Online (Sandbox Code Playgroud)