summaryrefslogtreecommitdiffstats
path: root/src/segment.rs
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2022-05-23 12:58:27 +0200
committerGitHub <noreply@github.com>2022-05-23 06:58:27 -0400
commit0ae61c775891b4dde1535c9224d44bc8d12899e2 (patch)
treead4aff77dbb15ecd046f1e897c0c84848fe662bc /src/segment.rs
parenta0a6c942fe3fc85d599aec883406224c9ecb589f (diff)
chore(clippy): fix new lints (#4002)
Diffstat (limited to 'src/segment.rs')
-rw-r--r--src/segment.rs44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/segment.rs b/src/segment.rs
index 643298c2d..cab7835d5 100644
--- a/src/segment.rs
+++ b/src/segment.rs
@@ -77,7 +77,7 @@ mod fill_seg_tests {
("🟢🔵🟡", "🟢🔵🟡🟢🔵"),
];
- for (text, expected) in inputs.iter() {
+ for (text, expected) in &inputs {
let f = FillSegment {
value: String::from(*text),
style: Some(style),
@@ -97,17 +97,17 @@ pub enum Segment {
}
impl Segment {
- /// Creates new segments from a text with a style; breaking out LineTerminators.
- pub fn from_text<T>(style: Option<Style>, value: T) -> Vec<Segment>
+ /// Creates new segments from a text with a style; breaking out `LineTerminators`.
+ pub fn from_text<T>(style: Option<Style>, value: T) -> Vec<Self>
where
T: Into<String>,
{
- let mut segs: Vec<Segment> = Vec::new();
+ let mut segs: Vec<Self> = Vec::new();
value.into().split(LINE_TERMINATOR).for_each(|s| {
if !segs.is_empty() {
- segs.push(Segment::LineTerm)
+ segs.push(Self::LineTerm)
}
- segs.push(Segment::Text(TextSegment {
+ segs.push(Self::Text(TextSegment {
value: String::from(s),
style,
}))
@@ -120,7 +120,7 @@ impl Segment {
where
T: Into<String>,
{
- Segment::Fill(FillSegment {
+ Self::Fill(FillSegment {
style,
value: value.into(),
})
@@ -128,50 +128,50 @@ impl Segment {
pub fn style(&self) -> Option<Style> {
match self {
- Segment::Fill(fs) => fs.style,
- Segment::Text(ts) => ts.style,
- Segment::LineTerm => None,
+ Self::Fill(fs) => fs.style,
+ Self::Text(ts) => ts.style,
+ Self::LineTerm => None,
}
}
pub fn set_style_if_empty(&mut self, style: Option<Style>) {
match self {
- Segment::Fill(fs) => {
+ Self::Fill(fs) => {
if fs.style.is_none() {
fs.style = style
}
}
- Segment::Text(ts) => {
+ Self::Text(ts) => {
if ts.style.is_none() {
ts.style = style
}
}
- Segment::LineTerm => {}
+ Self::LineTerm => {}
}
}
pub fn value(&self) -> &str {
match self {
- Segment::Fill(fs) => &fs.value,
- Segment::Text(ts) => &ts.value,
- Segment::LineTerm => LINE_TERMINATOR_STRING,
+ Self::Fill(fs) => &fs.value,
+ Self::Text(ts) => &ts.value,
+ Self::LineTerm => LINE_TERMINATOR_STRING,
}
}
// Returns the ANSIString of the segment value, not including its prefix and suffix
pub fn ansi_string(&self) -> ANSIString {
match self {
- Segment::Fill(fs) => fs.ansi_string(None),
- Segment::Text(ts) => ts.ansi_string(),
- Segment::LineTerm => ANSIString::from(LINE_TERMINATOR_STRING),
+ Self::Fill(fs) => fs.ansi_string(None),
+ Self::Text(ts) => ts.ansi_string(),
+ Self::LineTerm => ANSIString::from(LINE_TERMINATOR_STRING),
}
}
pub fn width_graphemes(&self) -> usize {
match self {
- Segment::Fill(fs) => fs.value.width_graphemes(),
- Segment::Text(ts) => ts.value.width_graphemes(),
- Segment::LineTerm => 0,
+ Self::Fill(fs) => fs.value.width_graphemes(),
+ Self::Text(ts) => ts.value.width_graphemes(),
+ Self::LineTerm => 0,
}
}
}