chore: allow Buffer::with_lines to accept IntoIterator (#901)

This can make it easier to use `Buffer::with_lines` with iterators that
don't necessarily produce a `Vec`. For example, this allows using
`Buffer::with_lines` with `&[&str]` directly, without having to call
`collect` on it first.
This commit is contained in:
Josh McKinney
2024-01-31 14:12:10 -08:00
committed by GitHub
parent 9ba7354335
commit f8367fdfdd
5 changed files with 12 additions and 13 deletions

View File

@@ -71,9 +71,10 @@ impl Buffer {
}
/// Returns a Buffer containing the given lines
pub fn with_lines<'a, S>(lines: Vec<S>) -> Buffer
pub fn with_lines<'a, Iter>(lines: Iter) -> Buffer
where
S: Into<Line<'a>>,
Iter: IntoIterator,
Iter::Item: Into<Line<'a>>,
{
let lines = lines.into_iter().map(Into::into).collect::<Vec<_>>();
let height = lines.len() as u16;