diff --git a/cursive-core/src/utils/span.rs b/cursive-core/src/utils/span.rs index ac05014..f0f35ae 100644 --- a/cursive-core/src/utils/span.rs +++ b/cursive-core/src/utils/span.rs @@ -3,6 +3,7 @@ //! This module defines various structs describing a span of text from a //! larger string. use std::borrow::Cow; +use std::iter::FromIterator; use unicode_width::UnicodeWidthStr; /// A string with associated spans. @@ -254,6 +255,22 @@ impl SpannedString { } } +impl FromIterator> for SpannedString { + fn from_iter>>( + iter: I, + ) -> SpannedString { + let mut iter = iter.into_iter(); + if let Some(first) = iter.next() { + iter.fold(first, |mut acc, s| { + acc.append(s); + acc + }) + } else { + SpannedString::new() + } + } +} + impl<'a, T> From<&'a SpannedString> for SpannedStr<'a, T> { fn from(other: &'a SpannedString) -> Self { SpannedStr::new(&other.source, &other.spans)