Skip to content

Commit

Permalink
Use matches!() macro to improve readability (rust-lang#5830)
Browse files Browse the repository at this point in the history
* Use matches!() macro to improve readability

1. Use `matches!()` macro in `is_line_comment` and `is_block_comment` to
improve readability.
2. Very sightly improve the wording of the doc comment for these two functions.

* Update wording on doc comment on is_line_comment()
  • Loading branch information
jmqd authored Jul 17, 2023
1 parent e9dfb6f commit e0e633e
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,23 @@ fn custom_opener(s: &str) -> &str {
}

impl<'a> CommentStyle<'a> {
/// Returns `true` if the commenting style covers a line only.
/// Returns `true` if the commenting style cannot span multiple lines.
pub(crate) fn is_line_comment(&self) -> bool {
match *self {
matches!(
self,
CommentStyle::DoubleSlash
| CommentStyle::TripleSlash
| CommentStyle::Doc
| CommentStyle::Custom(_) => true,
_ => false,
}
| CommentStyle::TripleSlash
| CommentStyle::Doc
| CommentStyle::Custom(_)
)
}

/// Returns `true` if the commenting style can span over multiple lines.
/// Returns `true` if the commenting style can span multiple lines.
pub(crate) fn is_block_comment(&self) -> bool {
match *self {
CommentStyle::SingleBullet | CommentStyle::DoubleBullet | CommentStyle::Exclamation => {
true
}
_ => false,
}
matches!(
self,
CommentStyle::SingleBullet | CommentStyle::DoubleBullet | CommentStyle::Exclamation
)
}

/// Returns `true` if the commenting style is for documentation.
Expand Down

0 comments on commit e0e633e

Please sign in to comment.