Skip to content

Commit c1aec5e

Browse files
committed
implement FromIterator also for &Tuple
I'm sick of writing `cloned` =)
1 parent 61952bb commit c1aec5e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ impl<Tuple: Ord> FromIterator<Tuple> for Relation<Tuple> {
148148
}
149149
}
150150

151+
impl<'tuple, Tuple: 'tuple + Copy + Ord> FromIterator<&'tuple Tuple> for Relation<Tuple> {
152+
fn from_iter<I>(iterator: I) -> Self
153+
where
154+
I: IntoIterator<Item = &'tuple Tuple>
155+
{
156+
Relation::from_vec(iterator.into_iter().cloned().collect())
157+
}
158+
}
159+
151160
impl<Tuple: Ord> std::ops::Deref for Relation<Tuple> {
152161
type Target = [Tuple];
153162
fn deref(&self) -> &Self::Target {

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<_> = edges.iter().cloned().collect();
34+
let edges: Relation<_> = edges.iter().collect();
3535
let mut iteration = Iteration::new();
3636

3737
// NB. Changed from `reachable_with_var_join`:

0 commit comments

Comments
 (0)