我可以仅将板条件属性应用于板条箱本身吗?

发布于 2025-02-08 09:07:21 字数 250 浏览 2 评论 0原文

我有一个生锈项目,需要一些带有滴定的二进制文件。因此,我创建了源文件,例如src/bin/myfoobinary.rssrc/bin/mybarbinary.rs。编译器警告说,这些二元板条箱应该具有蛇案的名称,我想抑制该警告。

我可以将#![lose(non_snake_case)]添加到板条箱中,但这也适用于板条箱的整个内容。不理想。我真的只想压制板条箱名称的警告。有可能吗?

I have a Rust project that needs a few binaries with TitleCaseNames. So I created source files like src/bin/MyFooBinary.rs and src/bin/MyBarBinary.rs. The compiler warns that these binary crates should have snake case names, and I want to suppress that warning.

I can add #![allow(non_snake_case)] to the crate, but that then applies to the crate's entire contents as well. Not ideal. I really only want to suppress the warning for the crate name. Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋凉 2025-02-15 09:07:21

我建议按照源文件和板条箱名称的常规snake_name约定。由于您需要在部署或包装期间将二进制文件移动到其他地方,因此您可以在此时重命名。

在夜间编译器构建中,您还可以指定与cargo.toml中的板条名称不同的文件名:

cargo-features = ["different-binary-name"]

[package]
# ...

[[bin]]
name = "foo_bar"
filename = "FooBar"
path = "src/bin/foo_bar.rs"

I'd suggest to follow the usual snake_name convention for the source file and crate names. Since you need to move the binaries elsewhere during deployment or packaging anyway, you can rename them at that point.

In the nightly compiler build, you can also specify a filename that is different from the crate name in Cargo.toml:

cargo-features = ["different-binary-name"]

[package]
# ...

[[bin]]
name = "foo_bar"
filename = "FooBar"
path = "src/bin/foo_bar.rs"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文