Skip to content

Commit 9990a34

Browse files
committed
Rename PointCollection::Borrow to Point
1 parent 437d477 commit 9990a34

File tree

10 files changed

+50
-23
lines changed

10 files changed

+50
-23
lines changed

src/element/basic_shapes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<Coord> Pixel<Coord> {
1818
}
1919

2020
impl<'a, Coord> PointCollection<'a, Coord> for &'a Pixel<Coord> {
21-
type Borrow = &'a Coord;
21+
type Point = &'a Coord;
2222
type IntoIter = std::iter::Once<&'a Coord>;
2323
fn point_iter(self) -> Self::IntoIter {
2424
std::iter::once(&self.pos)
@@ -81,7 +81,7 @@ impl<Coord> PathElement<Coord> {
8181
}
8282

8383
impl<'a, Coord> PointCollection<'a, Coord> for &'a PathElement<Coord> {
84-
type Borrow = &'a Coord;
84+
type Point = &'a Coord;
8585
type IntoIter = &'a [Coord];
8686
fn point_iter(self) -> &'a [Coord] {
8787
&self.points
@@ -153,7 +153,7 @@ impl<Coord> Rectangle<Coord> {
153153
}
154154

155155
impl<'a, Coord> PointCollection<'a, Coord> for &'a Rectangle<Coord> {
156-
type Borrow = &'a Coord;
156+
type Point = &'a Coord;
157157
type IntoIter = &'a [Coord];
158158
fn point_iter(self) -> &'a [Coord] {
159159
&self.points
@@ -245,7 +245,7 @@ impl<Coord, Size: SizeDesc> Circle<Coord, Size> {
245245
}
246246

247247
impl<'a, Coord, Size: SizeDesc> PointCollection<'a, Coord> for &'a Circle<Coord, Size> {
248-
type Borrow = &'a Coord;
248+
type Point = &'a Coord;
249249
type IntoIter = std::iter::Once<&'a Coord>;
250250
fn point_iter(self) -> std::iter::Once<&'a Coord> {
251251
std::iter::once(&self.center)
@@ -306,7 +306,7 @@ impl<Coord> Polygon<Coord> {
306306
}
307307

308308
impl<'a, Coord> PointCollection<'a, Coord> for &'a Polygon<Coord> {
309-
type Borrow = &'a Coord;
309+
type Point = &'a Coord;
310310
type IntoIter = &'a [Coord];
311311
fn point_iter(self) -> &'a [Coord] {
312312
&self.points

src/element/boxplot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ impl<K, O: BoxplotOrient<K, f32>> Boxplot<K, O> {
180180
impl<'a, K: Clone, O: BoxplotOrient<K, f32>> PointCollection<'a, (O::XType, O::YType)>
181181
for &'a Boxplot<K, O>
182182
{
183-
type Borrow = (O::XType, O::YType);
184-
type IntoIter = Vec<Self::Borrow>;
183+
type Point = (O::XType, O::YType);
184+
type IntoIter = Vec<Self::Point>;
185185
fn point_iter(self) -> Self::IntoIter {
186186
self.values
187187
.iter()

src/element/candlestick.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<X: Clone, Y: PartialOrd> CandleStick<X, Y> {
6262
}
6363

6464
impl<'a, X: 'a, Y: PartialOrd + 'a> PointCollection<'a, (X, Y)> for &'a CandleStick<X, Y> {
65-
type Borrow = &'a (X, Y);
65+
type Point = &'a (X, Y);
6666
type IntoIter = &'a [(X, Y)];
6767
fn point_iter(self) -> &'a [(X, Y)] {
6868
&self.points

src/element/composable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
}
3737

3838
impl<'a, Coord, DB: DrawingBackend> PointCollection<'a, Coord> for &'a EmptyElement<Coord, DB> {
39-
type Borrow = &'a Coord;
39+
type Point = &'a Coord;
4040
type IntoIter = Once<&'a Coord>;
4141
fn point_iter(self) -> Self::IntoIter {
4242
once(&self.coord)
@@ -64,7 +64,7 @@ pub struct BoxedElement<Coord, DB: DrawingBackend, A: Drawable<DB>> {
6464
impl<'b, Coord, DB: DrawingBackend, A: Drawable<DB>> PointCollection<'b, Coord>
6565
for &'b BoxedElement<Coord, DB, A>
6666
{
67-
type Borrow = &'b Coord;
67+
type Point = &'b Coord;
6868
type IntoIter = Once<&'b Coord>;
6969
fn point_iter(self) -> Self::IntoIter {
7070
once(&self.offset)
@@ -132,7 +132,7 @@ where
132132
A: Drawable<DB>,
133133
B: Drawable<DB>,
134134
{
135-
type Borrow = &'b Coord;
135+
type Point = &'b Coord;
136136
type IntoIter = Once<&'b Coord>;
137137
fn point_iter(self) -> Self::IntoIter {
138138
once(&self.offset)

src/element/dynelem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
impl<'a, 'b: 'a, DB: DrawingBackend, Coord: Clone> PointCollection<'a, Coord>
3737
for &'a DynElement<'b, DB, Coord>
3838
{
39-
type Borrow = &'a Coord;
39+
type Point = &'a Coord;
4040
type IntoIter = &'a Vec<Coord>;
4141
fn point_iter(self) -> Self::IntoIter {
4242
&self.points

src/element/errorbar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ impl<K, V> ErrorBar<K, V, ErrorBarOrientH<K, V>> {
9797
impl<'a, K: Clone, V: Clone, O: ErrorBarOrient<K, V>> PointCollection<'a, (O::XType, O::YType)>
9898
for &'a ErrorBar<K, V, O>
9999
{
100-
type Borrow = (O::XType, O::YType);
101-
type IntoIter = Vec<Self::Borrow>;
100+
type Point = (O::XType, O::YType);
101+
type IntoIter = Vec<Self::Point>;
102102
fn point_iter(self) -> Self::IntoIter {
103103
self.values
104104
.iter()

src/element/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a, Coord> From<(Coord, DynamicImage)> for BitMapElement<'a, Coord, BGRXPix
193193
}
194194

195195
impl<'a, 'b, Coord> PointCollection<'a, Coord> for &'a BitMapElement<'b, Coord> {
196-
type Borrow = &'a Coord;
196+
type Point = &'a Coord;
197197
type IntoIter = std::iter::Once<&'a Coord>;
198198
fn point_iter(self) -> Self::IntoIter {
199199
std::iter::once(&self.pos)

src/element/mod.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
// For any reference to RedX, we can convert it into an iterator of points
3232
impl <'a> PointCollection<'a, (i32, i32)> for &'a RedBoxedX {
33-
type Borrow = &'a (i32, i32);
33+
type Point = &'a (i32, i32);
3434
type IntoIter = Once<&'a (i32, i32)>;
3535
fn point_iter(self) -> Self::IntoIter {
3636
once(&self.0)
@@ -192,13 +192,40 @@ pub use self::image::BitMapElement;
192192
mod dynelem;
193193
pub use dynelem::{DynElement, IntoDynElement};
194194

195-
/// A type which is logically a collection of points, under any given coordinate system
195+
/// A type which is logically a collection of points, under any given coordinate system.
196+
/// Note: Ideally, a point collection trait should be any type of which coordinate elements can be
197+
/// iterated. This is similar to `iter` method of many collection types in std.
198+
///
199+
/// ```ignore
200+
/// trait PointCollection<Coord> {
201+
/// type PointIter<'a> : Iterator<Item = &'a Coord>;
202+
/// fn iter(&self) -> PointIter<'a>;
203+
/// }
204+
/// ```
205+
///
206+
/// However,
207+
/// [Generic Associated Types](https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md)
208+
/// is far away from stablize.
209+
/// So currently we have the following workaround:
210+
///
211+
/// Instead of implement the PointCollection trait on the element type itself, it implements on the
212+
/// reference to the element. By doing so, we now have a well-defined lifetime for the iterator.
213+
///
214+
/// In addition, for some element, the coordinate is computed on the fly, thus we can't hard-code
215+
/// the iterator's return type is `&'a Coord`.
216+
/// `Borrow` trait seems to strict in this case, since we don't need the order and hash
217+
/// preservation properties at this point. However, `AsRef` doesn't work with `Coord`
218+
///
219+
/// This workaround also leads overly strict lifetime bound on `ChartContext::draw_series`.
220+
///
221+
/// TODO: Once GAT is ready on stable Rust, we should simplify the design.
222+
///
196223
pub trait PointCollection<'a, Coord> {
197224
/// The item in point iterator
198-
type Borrow: Borrow<Coord>;
225+
type Point: Borrow<Coord> + 'a;
199226

200227
/// The point iterator
201-
type IntoIter: IntoIterator<Item = Self::Borrow>;
228+
type IntoIter: IntoIterator<Item = Self::Point>;
202229

203230
/// framework to do the coordinate mapping
204231
fn point_iter(self) -> Self::IntoIter;

src/element/points.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<Coord, Size: SizeDesc> Cross<Coord, Size> {
2626
}
2727

2828
impl<'a, Coord: 'a, Size: SizeDesc> PointCollection<'a, Coord> for &'a Cross<Coord, Size> {
29-
type Borrow = &'a Coord;
29+
type Point = &'a Coord;
3030
type IntoIter = std::iter::Once<&'a Coord>;
3131
fn point_iter(self) -> std::iter::Once<&'a Coord> {
3232
std::iter::once(&self.center)
@@ -69,7 +69,7 @@ impl<Coord, Size: SizeDesc> TriangleMarker<Coord, Size> {
6969
}
7070

7171
impl<'a, Coord: 'a, Size: SizeDesc> PointCollection<'a, Coord> for &'a TriangleMarker<Coord, Size> {
72-
type Borrow = &'a Coord;
72+
type Point = &'a Coord;
7373
type IntoIter = std::iter::Once<&'a Coord>;
7474
fn point_iter(self) -> std::iter::Once<&'a Coord> {
7575
std::iter::once(&self.center)

src/element/text.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a, Coord, T: Borrow<str>> Text<'a, Coord, T> {
2929
}
3030

3131
impl<'b, 'a, Coord: 'a, T: Borrow<str> + 'a> PointCollection<'a, Coord> for &'a Text<'b, Coord, T> {
32-
type Borrow = &'a Coord;
32+
type Point = &'a Coord;
3333
type IntoIter = std::iter::Once<&'a Coord>;
3434
fn point_iter(self) -> Self::IntoIter {
3535
std::iter::once(&self.coord)
@@ -216,7 +216,7 @@ impl<'a, Coord> MultiLineText<'a, Coord, String> {
216216
impl<'b, 'a, Coord: 'a, T: Borrow<str> + 'a> PointCollection<'a, Coord>
217217
for &'a MultiLineText<'b, Coord, T>
218218
{
219-
type Borrow = &'a Coord;
219+
type Point = &'a Coord;
220220
type IntoIter = std::iter::Once<&'a Coord>;
221221
fn point_iter(self) -> Self::IntoIter {
222222
std::iter::once(&self.coord)

0 commit comments

Comments
 (0)