summaryrefslogtreecommitdiff
path: root/helix-tui/src/text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-tui/src/text.rs')
-rw-r--r--helix-tui/src/text.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/helix-tui/src/text.rs b/helix-tui/src/text.rs
index 8a974ddb..b4278c86 100644
--- a/helix-tui/src/text.rs
+++ b/helix-tui/src/text.rs
@@ -194,6 +194,12 @@ impl<'a> From<&'a str> for Span<'a> {
}
}
+impl<'a> From<Cow<'a, str>> for Span<'a> {
+ fn from(s: Cow<'a, str>) -> Span<'a> {
+ Span::raw(s)
+ }
+}
+
/// A string composed of clusters of graphemes, each with their own style.
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Spans<'a>(pub Vec<Span<'a>>);
@@ -229,6 +235,12 @@ impl<'a> From<&'a str> for Spans<'a> {
}
}
+impl<'a> From<Cow<'a, str>> for Spans<'a> {
+ fn from(s: Cow<'a, str>) -> Spans<'a> {
+ Spans(vec![Span::raw(s)])
+ }
+}
+
impl<'a> From<Vec<Span<'a>>> for Spans<'a> {
fn from(spans: Vec<Span<'a>>) -> Spans<'a> {
Spans(spans)
@@ -243,10 +255,13 @@ impl<'a> From<Span<'a>> for Spans<'a> {
impl<'a> From<Spans<'a>> for String {
fn from(line: Spans<'a>) -> String {
- line.0.iter().fold(String::new(), |mut acc, s| {
- acc.push_str(s.content.as_ref());
- acc
- })
+ line.0.iter().map(|s| &*s.content).collect()
+ }
+}
+
+impl<'a> From<&Spans<'a>> for String {
+ fn from(line: &Spans<'a>) -> String {
+ line.0.iter().map(|s| &*s.content).collect()
}
}