summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Laitl <matej@laitl.cz>2019-02-20 18:46:39 +0100
committerMatěj Laitl <matej@laitl.cz>2019-02-20 18:46:39 +0100
commit5958c92c639e54606bae15ab61ee0c49577a791e (patch)
tree98250120b73be1f946e7eb0018ed8054efc399fe
parent71996be958e3c5155e372f250e5f00fd3c61366d (diff)
Convert into CalendarComponent in Calendar::extend()
Previously, one needed to pass IntoIterator<CalendarElement>, but CalendarElement is in private module `calendar` (and not re-exported). Now this also becomes symmetric with other addition methods that allow Into<CalendarElement>.
-rw-r--r--src/calendar.rs18
1 files 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<T>(&mut self, other: T)
- where T: IntoIterator<Item=CalendarElement>
+ pub fn extend<T, U>(&mut self, other: T)
+ where T: IntoIterator<Item=U>,
+ U: Into<CalendarElement>
{
- 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);
+ }
}