Remove comments from
Rust code.
Remove comments from Rust source code online. Correctly handles nested block comments and raw string literals, the two features that break most regex-based tools.
.rs filesBefore and after
Real-world Rust code on the left. The same code with every comment removed on the right.
//! Order processing module.
// Re-exports
pub use crate::repo::Repository;
/// A single customer order.
///
/// /* outer block /* with nested */ comment */
pub struct Order {
pub id: String, // unique identifier
pub total_cents: u64, /* amount due */
}
/* Helpers */
fn raw_query() -> &'static str {
r#"SELECT * FROM orders WHERE note = "// not a comment""#
}
// Public API
pub fn find_by_id(id: &str) -> Option<Order> {
if id.is_empty() { return None; } // guard
None
}pub use crate::repo::Repository;
pub struct Order {
pub id: String,
pub total_cents: u64,
}
fn raw_query() -> &'static str {
r#"SELECT * FROM orders WHERE note = "// not a comment""#
}
pub fn find_by_id(id: &str) -> Option<Order> {
if id.is_empty() { return None; }
None
}Built for Rust specifically.
Rust documentation comments (/// and //!) are dense, and macro-heavy code can pile up `//` notes faster than in most languages. Removing comments is helpful before sharing a snippet, comparing implementations, or producing a compact teaching example. The hard parts of Rust, nested block comments and raw strings like r#"..."#, are exactly where naive strippers fall apart. Uncommenter handles both correctly.
- // and /* */ comments removed
- Nested /* /* */ */ block comments handled to full depth
- /// outer doc and //! inner doc comments removed
- Raw string literals r#"..."# preserved verbatim
- Auto-detected from .rs files
Strip comments in 30 seconds.
- 1
Open the tool
Head to uncommenter.com/tool. Nothing to install. Nothing to sign up for.
- 2
Paste your Rust code
Drop your .rs file in, or paste code into the editor. Auto-detection picks up Rust from the extension or file content.
- 3
Click 'Remove Comments'
The parser walks every character with a real state machine, strings, regex, and other context-sensitive parts are detected and left alone.
- 4
Copy or download
Grab the cleaned output. Your code never left your browser.
Rust questions, answered.
Does it handle nested block comments correctly?
+
Yes, Rust's spec allows arbitrary nesting depth for /* */ blocks, and the parser tracks depth explicitly. /* outer /* inner */ still outer */ is removed as a single comment.
What about raw strings with hashes?
+
r"...", r#"..."#, r##"..."##, and so on are all recognized. Anything inside is treated as content, including // and /*.
Will it remove documentation comments?
+
/// outer doc comments and //! inner doc comments are removed by default. They use line-comment syntax in Rust, so they're treated like regular line comments.
Working in something else?
Plus 35+ more languages supported in the live tool , including HTML, YAML, Dockerfile, Terraform, Solidity, and more.
Try it on your Rust code now.
Free forever. No signup. No upload. Runs entirely in your browser.
Open uncommenter