1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::element::PointElement;
use crate::style::ShapeStyle;
pub struct PointSeries<'a, Coord, I: IntoIterator<Item = Coord>, E> {
style: ShapeStyle,
size: u32,
data_iter: I::IntoIter,
make_point: &'a dyn Fn(Coord, u32, ShapeStyle) -> E,
}
impl<'a, Coord, I: IntoIterator<Item = Coord>, E> Iterator for PointSeries<'a, Coord, I, E> {
type Item = E;
fn next(&mut self) -> Option<Self::Item> {
self.data_iter
.next()
.map(|x| (self.make_point)(x, self.size, self.style.clone()))
}
}
impl<'a, Coord, I: IntoIterator<Item = Coord>, E> PointSeries<'a, Coord, I, E>
where
E: PointElement<Coord>,
{
pub fn new<S: Into<ShapeStyle>>(iter: I, size: u32, style: S) -> Self {
Self {
data_iter: iter.into_iter(),
size,
style: style.into(),
make_point: &|a, b, c| E::make_point(a, b, c),
}
}
}
impl<'a, Coord, I: IntoIterator<Item = Coord>, E> PointSeries<'a, Coord, I, E> {
pub fn of_element<S: Into<ShapeStyle>, F: Fn(Coord, u32, ShapeStyle) -> E>(
iter: I,
size: u32,
style: S,
cons: &'a F,
) -> Self {
Self {
data_iter: iter.into_iter(),
size,
style: style.into(),
make_point: cons,
}
}
}