Skip to content

Instantly share code, notes, and snippets.

@chrissimpkins
Last active March 5, 2020 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrissimpkins/4b442351038c8926195f7cdea74c9659 to your computer and use it in GitHub Desktop.
Save chrissimpkins/4b442351038c8926195f7cdea74c9659 to your computer and use it in GitHub Desktop.
Approach for removal of comments with syn crate
struct CommentRemove;
impl VisitMut for CommentRemove {
fn visit_attribute_mut(&mut self, node: &mut Attribute) {
// identify comments
if node.path.is_ident("doc") {
println!("{:?}", node.tokens);
println!("{:?}", node.path);
// can you "null" out the Attribute in some way so that the comments are removed when you transform back into Rust text source?
// or is there a different approach?
node = &mut Attribute{
bracket_token: None,
pound_token: None,
style: None,
path: None,
tokens: None,
};
}
visit_mut::visit_attribute_mut(self, node);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment