Make column and row take an IntoIterator

This commit is contained in:
Héctor Ramón Jiménez 2024-01-09 06:46:49 +01:00
parent e710e76949
commit 67277fbf93
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 8 additions and 10 deletions

View file

@ -41,9 +41,9 @@ where
/// Creates a [`Column`] with the given elements. /// Creates a [`Column`] with the given elements.
pub fn with_children( pub fn with_children(
children: impl Iterator<Item = Element<'a, Message, Renderer>>, children: impl IntoIterator<Item = Element<'a, Message, Renderer>>,
) -> Self { ) -> Self {
children.fold(Self::new(), |column, element| column.push(element)) children.into_iter().fold(Self::new(), Self::push)
} }
/// Sets the vertical spacing _between_ elements. /// Sets the vertical spacing _between_ elements.

View file

@ -34,7 +34,7 @@ macro_rules! column {
$crate::Column::new() $crate::Column::new()
); );
($($x:expr),+ $(,)?) => ( ($($x:expr),+ $(,)?) => (
$crate::Column::with_children([$($crate::core::Element::from($x)),+].into_iter()) $crate::Column::with_children([$($crate::core::Element::from($x)),+])
); );
} }
@ -47,7 +47,7 @@ macro_rules! row {
$crate::Row::new() $crate::Row::new()
); );
($($x:expr),+ $(,)?) => ( ($($x:expr),+ $(,)?) => (
$crate::Row::with_children([$($crate::core::Element::from($x)),+].into_iter()) $crate::Row::with_children([$($crate::core::Element::from($x)),+])
); );
} }
@ -66,7 +66,7 @@ where
/// Creates a new [`Column`] with the given children. /// Creates a new [`Column`] with the given children.
pub fn column<'a, Message, Renderer>( pub fn column<'a, Message, Renderer>(
children: impl Iterator<Item = Element<'a, Message, Renderer>>, children: impl IntoIterator<Item = Element<'a, Message, Renderer>>,
) -> Column<'a, Message, Renderer> ) -> Column<'a, Message, Renderer>
where where
Renderer: core::Renderer, Renderer: core::Renderer,
@ -89,7 +89,7 @@ where
/// ///
/// [`Row`]: crate::Row /// [`Row`]: crate::Row
pub fn row<'a, Message, Renderer>( pub fn row<'a, Message, Renderer>(
children: impl Iterator<Item = Element<'a, Message, Renderer>>, children: impl IntoIterator<Item = Element<'a, Message, Renderer>>,
) -> Row<'a, Message, Renderer> ) -> Row<'a, Message, Renderer>
where where
Renderer: core::Renderer, Renderer: core::Renderer,

View file

@ -39,11 +39,9 @@ where
/// Creates a [`Row`] with the given elements. /// Creates a [`Row`] with the given elements.
pub fn with_children( pub fn with_children(
children: impl Iterator<Item = Element<'a, Message, Renderer>>, children: impl IntoIterator<Item = Element<'a, Message, Renderer>>,
) -> Self { ) -> Self {
children children.into_iter().fold(Self::new(), Self::push)
.into_iter()
.fold(Self::new(), |column, element| column.push(element))
} }
/// Sets the horizontal spacing _between_ elements. /// Sets the horizontal spacing _between_ elements.