Cleanup fold code and split logic to fold single elements
This commit is contained in:
@@ -100,8 +100,8 @@ impl<'a> Lifetime<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Comment<'a> {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
self.syntax().leaf_text().unwrap().clone()
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
self.syntax().leaf_text().unwrap()
|
||||
}
|
||||
|
||||
pub fn flavor(&self) -> CommentFlavor {
|
||||
@@ -120,6 +120,14 @@ impl<'a> Comment<'a> {
|
||||
pub fn prefix(&self) -> &'static str {
|
||||
self.flavor().prefix()
|
||||
}
|
||||
|
||||
pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> {
|
||||
self.text().chars().filter(|&c| c == '\n').map(|_| &())
|
||||
}
|
||||
|
||||
pub fn has_newlines(&self) -> bool {
|
||||
self.count_newlines_lazy().count() > 0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -142,6 +150,20 @@ impl CommentFlavor {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Whitespace<'a> {
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
&self.syntax().leaf_text().unwrap()
|
||||
}
|
||||
|
||||
pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> {
|
||||
self.text().chars().filter(|&c| c == '\n').map(|_| &())
|
||||
}
|
||||
|
||||
pub fn has_newlines(&self) -> bool {
|
||||
self.count_newlines_lazy().count() > 0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Name<'a> {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
let ident = self.syntax().first_child()
|
||||
|
||||
Reference in New Issue
Block a user