英文:
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();
// */
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论