|
30 | 30 |
|
31 | 31 | // For any reference to RedX, we can convert it into an iterator of points |
32 | 32 | impl <'a> PointCollection<'a, (i32, i32)> for &'a RedBoxedX { |
33 | | - type Borrow = &'a (i32, i32); |
| 33 | + type Point = &'a (i32, i32); |
34 | 34 | type IntoIter = Once<&'a (i32, i32)>; |
35 | 35 | fn point_iter(self) -> Self::IntoIter { |
36 | 36 | once(&self.0) |
@@ -192,13 +192,40 @@ pub use self::image::BitMapElement; |
192 | 192 | mod dynelem; |
193 | 193 | pub use dynelem::{DynElement, IntoDynElement}; |
194 | 194 |
|
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 | +/// |
196 | 223 | pub trait PointCollection<'a, Coord> { |
197 | 224 | /// The item in point iterator |
198 | | - type Borrow: Borrow<Coord>; |
| 225 | + type Point: Borrow<Coord> + 'a; |
199 | 226 |
|
200 | 227 | /// The point iterator |
201 | | - type IntoIter: IntoIterator<Item = Self::Borrow>; |
| 228 | + type IntoIter: IntoIterator<Item = Self::Point>; |
202 | 229 |
|
203 | 230 | /// framework to do the coordinate mapping |
204 | 231 | fn point_iter(self) -> Self::IntoIter; |
|
0 commit comments