Search code examples
rustcomments

Quickly (un)comment blocks of code in 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?


Solution

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

    /*
    commented_out();
    // */
    
    //*
    not_commented();
    // */