Skip to content

Commit 61952bb

Browse files
committed
implement FromIterator so you can collect into a tuple
1 parent 359f92f commit 61952bb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use std::cell::RefCell;
1515
use std::cmp::Ordering;
1616
use std::rc::Rc;
17+
use std::iter::FromIterator;
1718

1819
mod join;
1920
mod map;
@@ -134,6 +135,15 @@ impl<Tuple: Ord> Relation<Tuple> {
134135

135136
impl<Tuple: Ord, I: IntoIterator<Item = Tuple>> From<I> for Relation<Tuple> {
136137
fn from(iterator: I) -> Self {
138+
Self::from_iter(iterator)
139+
}
140+
}
141+
142+
impl<Tuple: Ord> FromIterator<Tuple> for Relation<Tuple> {
143+
fn from_iter<I>(iterator: I) -> Self
144+
where
145+
I: IntoIterator<Item = Tuple>
146+
{
137147
Relation::from_vec(iterator.into_iter().collect())
138148
}
139149
}

src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn reachable_with_var_join(edges: &[(u32, u32)]) -> Relation<(u32, u32)> {
3131

3232
/// Like `reachable`, but using a relation as an input to `from_join`
3333
fn reachable_with_relation_join(edges: &[(u32, u32)]) -> Relation<(u32, u32)> {
34-
let edges = Relation::from(edges.iter().cloned());
34+
let edges: Relation<_> = edges.iter().cloned().collect();
3535
let mut iteration = Iteration::new();
3636

3737
// NB. Changed from `reachable_with_var_join`:

0 commit comments

Comments
 (0)