格式多行字符串字面参数,没有额外的行

发布于 2025-01-26 12:10:17 字数 499 浏览 3 评论 0 原文

我想用单个多行字符串参数调用宏,像这样的格式:

css!(r"
    background: grey;
    color: white;
");

但是,rustfmt坚持将字符串字面的字样贴在自己的行上,这

css!(
    r"
    background: grey;
    color: white;
"
);

很丑即使有多行?

我知道Rustfmt可以是配置,,,,但是我找不到这个选择,我真的不知道要搜索什么。

I would like to call macros with a single multi-line string argument, formatted like so:

css!(r"
    background: grey;
    color: white;
");

However, Rustfmt insists on putting the string literal on its own line, which is ugly and takes up more space:

css!(
    r"
    background: grey;
    color: white;
"
);

Is there a way I can tell Rustfmt to not put a single string literal on its own line, even when it has multiple lines?

I am aware that Rustfmt can be configured, but I couldn't find an option for this and I don't really know what to search for.

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

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

发布评论

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

评论(1

维持三分热 2025-02-02 12:10:17

您可以使用#[Rustfmt :: Skip] 告诉Rustfmt不要格式化代码:

#[rustfmt::skip]
css!(r"
background: grey;
color: white;
");

Rustfmt还跳过支撑宏,因此您也可以这样做:

css! { r"
background: grey;
color: white;
" };

您也可以使用##[Rustfmt :: Skip:skip:skip:skip: :macros(...)] 始终跳过此宏:

#[rustfmt::skip::macros(css)]
fn foo() { ... }

全部应用(请参阅使用内部属性,但这是不稳定的:

#![feature(custom_inner_attributes)]
#![rustfmt::skip::macros(css)]

You can use #[rustfmt::skip] to tell rustfmt to not format code:

#[rustfmt::skip]
css!(r"
background: grey;
color: white;
");

rustfmt also skips braced macros, so you can do:

css! { r"
background: grey;
color: white;
" };

You can also use #[rustfmt::skip::macros(...)] to always skip this macro:

#[rustfmt::skip::macros(css)]
fn foo() { ... }

To apply it whole-file (see Is there a stable way to tell Rustfmt to skip an entire file), you can either apply it to the module declaration, or use an inner attribute, but that's unstable:

#![feature(custom_inner_attributes)]
#![rustfmt::skip::macros(css)]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文