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

use namespace instead of folder name

假设我有一个项目:

foo-bar
  | - lib.rs
  | - ....

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

您可以在Cargo.toml中指定库的名称,参见Cargo documentation

[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"