Skip to content

Commit afbe45d

Browse files
authored
add FromIterator for BoltType (#235)
1 parent 8dbbaea commit afbe45d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/src/convert.rs

+23
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ impl<A: Into<BoltType> + Clone> From<Vec<A>> for BoltType {
305305
}
306306
}
307307

308+
impl<T: Into<BoltType>> FromIterator<T> for BoltType {
309+
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
310+
BoltType::List(BoltList {
311+
value: iter.into_iter().map(Into::into).collect(),
312+
})
313+
}
314+
}
315+
308316
impl<A: Into<BoltType> + Clone> From<&[A]> for BoltType {
309317
fn from(value: &[A]) -> Self {
310318
BoltType::List(BoltList {
@@ -617,4 +625,19 @@ mod tests {
617625
})
618626
);
619627
}
628+
629+
#[test]
630+
fn convert_from_iterator() {
631+
let value: Vec<i64> = vec![42, 1337];
632+
let value: BoltType = value.into_iter().collect();
633+
assert_eq!(
634+
value,
635+
BoltType::List(BoltList {
636+
value: vec![
637+
BoltType::Integer(BoltInteger::new(42)),
638+
BoltType::Integer(BoltInteger::new(1337)),
639+
],
640+
})
641+
);
642+
}
620643
}

lib/src/types/list.rs

+8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ impl IntoIterator for BoltList {
6262
}
6363
}
6464

65+
impl<T: Into<BoltType>> FromIterator<T> for BoltList {
66+
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
67+
BoltList {
68+
value: iter.into_iter().map(Into::into).collect(),
69+
}
70+
}
71+
}
72+
6573
impl From<BoltList> for Vec<String> {
6674
fn from(value: BoltList) -> Self {
6775
value.value.into_iter().map(|x| x.to_string()).collect()

0 commit comments

Comments
 (0)