typstyle_core/ext.rs
1pub trait BoolExt {
2 fn replace(&mut self, value: Self) -> Self;
3}
4
5impl BoolExt for bool {
6 fn replace(&mut self, value: Self) -> Self {
7 let old = *self;
8 *self = value;
9 old
10 }
11}
12
13pub trait StrExt {
14 fn has_linebreak(&self) -> bool;
15
16 fn count_linebreaks(&self) -> usize;
17}
18
19impl StrExt for str {
20 fn has_linebreak(&self) -> bool {
21 self.contains('\n')
22 }
23
24 fn count_linebreaks(&self) -> usize {
25 self.chars().filter(|c| *c == '\n').count()
26 }
27}