From 5958c92c639e54606bae15ab61ee0c49577a791e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Laitl?= Date: Wed, 20 Feb 2019 18:46:39 +0100 Subject: Convert into CalendarComponent in Calendar::extend() Previously, one needed to pass IntoIterator, but CalendarElement is in private module `calendar` (and not re-exported). Now this also becomes symmetric with other addition methods that allow Into. --- src/calendar.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/calendar.rs b/src/calendar.rs index d492345..377ba56 100644 --- a/src/calendar.rs +++ b/src/calendar.rs @@ -59,10 +59,11 @@ impl Calendar { } /// Extends this `Calendar` with the contends of another. - pub fn extend(&mut self, other: T) - where T: IntoIterator + pub fn extend(&mut self, other: T) + where T: IntoIterator, + U: Into { - self.components.extend(other); + self.components.extend(other.into_iter().map(|x| x.into())); } /// Appends an element to the back of the `Calendar`. @@ -126,4 +127,15 @@ mod tests { calendar.extend(components); assert_eq!(calendar.components.len(), 2); } + + #[test] + fn calendar_extend_events() { + let mut calendar = Calendar::new(); + let events = vec![ + Event::new(), + Event::new(), + ]; + calendar.extend(events); + assert_eq!(calendar.components.len(), 2); + } } -- cgit v1.2.3