在Rust中快速(取消)注释代码块。

huangapple go评论60阅读模式
英文:

Quickly (un)comment blocks of code in Rust

问题

在像Java这样的语言中,我经常使用以下模式来快速注释/取消注释整个代码块:

/* *
hello.world();
/* */

// 我只需要添加一个'/',代码块就被取消注释:

/* */
hello.world();
/* */

然而,在Rust中,上面的代码会创建一个语法错误,因为在Rust文件中不允许有不相等数量的/**/

但是在Rust中是否有一种类似的快速注释/取消注释代码块的方法,而不涉及使用编辑器宏命令?

英文:

In languages such as Java, I often use the following pattern for quickly commenting/uncommenting whole blocks of code:

/* *
hello.world();
/* */

// I just have to add one '/' and the block is uncommented:

/* */
hello.world();
/* */

However, in Rust, the above code creates a syntax error, as it is not allowed to have unequal numbers of /* and */ in a Rust file.

But is there a similar way for quickly commenting/uncommenting blocks in Rust that does not involve using editor macro-commands?

答案1

得分: 1

你可以使用单行注释来激活/停用多行注释,例如:

/*
commented_out();
// */

/*
not_commented();
// */
英文:

You can use single-line comments to activate/deactivate your multi-lines comment, e.g.

/*
commented_out();
// */

//*
not_commented();
// */

huangapple
  • 本文由 发表于 2023年2月8日 17:46:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383906.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定