From 875e6421fd249d50b3cc9b2bfec94de26df4f6b1 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 5 Nov 2024 09:39:05 -0500 Subject: [PATCH] Remove associated type `T` on `geo-traits` traits. --- geo-traits/src/geometry.rs | 227 +++++++++++++++++++------- geo-traits/src/geometry_collection.rs | 14 +- geo-traits/src/iterator.rs | 37 ++--- geo-traits/src/line.rs | 23 +-- geo-traits/src/line_string.rs | 23 +-- geo-traits/src/multi_line_string.rs | 23 +-- geo-traits/src/multi_point.rs | 23 +-- geo-traits/src/multi_polygon.rs | 23 +-- geo-traits/src/polygon.rs | 22 +-- 9 files changed, 263 insertions(+), 152 deletions(-) diff --git a/geo-traits/src/geometry.rs b/geo-traits/src/geometry.rs index c781a418e..e61942142 100644 --- a/geo-traits/src/geometry.rs +++ b/geo-traits/src/geometry.rs @@ -12,56 +12,53 @@ use crate::{ /// A trait for accessing data from a generic Geometry. #[allow(clippy::type_complexity)] pub trait GeometryTrait { - /// The coordinate type of this geometry - type T; - /// The type of each underlying Point, which implements [PointTrait] - type PointType<'a>: 'a + PointTrait + type PointType<'a>: 'a + PointTrait where Self: 'a; /// The type of each underlying LineString, which implements [LineStringTrait] - type LineStringType<'a>: 'a + LineStringTrait + type LineStringType<'a>: 'a + LineStringTrait where Self: 'a; /// The type of each underlying Polygon, which implements [PolygonTrait] - type PolygonType<'a>: 'a + PolygonTrait + type PolygonType<'a>: 'a + PolygonTrait where Self: 'a; /// The type of each underlying MultiPoint, which implements [MultiPointTrait] - type MultiPointType<'a>: 'a + MultiPointTrait + type MultiPointType<'a>: 'a + MultiPointTrait where Self: 'a; /// The type of each underlying MultiLineString, which implements [MultiLineStringTrait] - type MultiLineStringType<'a>: 'a + MultiLineStringTrait + type MultiLineStringType<'a>: 'a + MultiLineStringTrait where Self: 'a; /// The type of each underlying MultiPolygon, which implements [MultiPolygonTrait] - type MultiPolygonType<'a>: 'a + MultiPolygonTrait + type MultiPolygonType<'a>: 'a + MultiPolygonTrait where Self: 'a; /// The type of each underlying GeometryCollection, which implements [GeometryCollectionTrait] - type GeometryCollectionType<'a>: 'a + GeometryCollectionTrait + type GeometryCollectionType<'a>: 'a + GeometryCollectionTrait where Self: 'a; /// The type of each underlying Rect, which implements [RectTrait] - type RectType<'a>: 'a + RectTrait + type RectType<'a>: 'a + RectTrait where Self: 'a; /// The type of each underlying Triangle, which implements [TriangleTrait] - type TriangleType<'a>: 'a + TriangleTrait + type TriangleType<'a>: 'a + TriangleTrait where Self: 'a; /// The type of each underlying Line, which implements [LineTrait] - type LineType<'a>: 'a + LineTrait + type LineType<'a>: 'a + LineTrait where Self: 'a; @@ -127,17 +124,46 @@ where #[cfg(feature = "geo-types")] impl<'a, T: CoordNum + 'a> GeometryTrait for Geometry { - type T = T; - type PointType<'b> = Point where Self: 'b; - type LineStringType<'b> = LineString where Self: 'b; - type PolygonType<'b> = Polygon where Self: 'b; - type MultiPointType<'b> = MultiPoint where Self: 'b; - type MultiLineStringType<'b> = MultiLineString where Self: 'b; - type MultiPolygonType<'b> = MultiPolygon where Self: 'b; - type GeometryCollectionType<'b> = GeometryCollection where Self: 'b; - type RectType<'b> = Rect where Self: 'b; - type TriangleType<'b> = Triangle where Self: 'b; - type LineType<'b> = Line where Self: 'b; + type PointType<'b> + = Point + where + Self: 'b; + type LineStringType<'b> + = LineString + where + Self: 'b; + type PolygonType<'b> + = Polygon + where + Self: 'b; + type MultiPointType<'b> + = MultiPoint + where + Self: 'b; + type MultiLineStringType<'b> + = MultiLineString + where + Self: 'b; + type MultiPolygonType<'b> + = MultiPolygon + where + Self: 'b; + type GeometryCollectionType<'b> + = GeometryCollection + where + Self: 'b; + type RectType<'b> + = Rect + where + Self: 'b; + type TriangleType<'b> + = Triangle + where + Self: 'b; + type LineType<'b> + = Line + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -175,17 +201,46 @@ impl<'a, T: CoordNum + 'a> GeometryTrait for Geometry { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum + 'a> GeometryTrait for &'a Geometry { - type T = T; - type PointType<'b> = Point where Self: 'b; - type LineStringType<'b> = LineString where Self: 'b; - type PolygonType<'b> = Polygon where Self: 'b; - type MultiPointType<'b> = MultiPoint where Self: 'b; - type MultiLineStringType<'b> = MultiLineString where Self: 'b; - type MultiPolygonType<'b> = MultiPolygon where Self: 'b; - type GeometryCollectionType<'b> = GeometryCollection where Self: 'b; - type RectType<'b> = Rect where Self: 'b; - type TriangleType<'b> = Triangle where Self: 'b; - type LineType<'b> = Line where Self: 'b; + type PointType<'b> + = Point + where + Self: 'b; + type LineStringType<'b> + = LineString + where + Self: 'b; + type PolygonType<'b> + = Polygon + where + Self: 'b; + type MultiPointType<'b> + = MultiPoint + where + Self: 'b; + type MultiLineStringType<'b> + = MultiLineString + where + Self: 'b; + type MultiPolygonType<'b> + = MultiPolygon + where + Self: 'b; + type GeometryCollectionType<'b> + = GeometryCollection + where + Self: 'b; + type RectType<'b> + = Rect + where + Self: 'b; + type TriangleType<'b> + = Triangle + where + Self: 'b; + type LineType<'b> + = Line + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -227,17 +282,46 @@ macro_rules! impl_specialization { ($geometry_type:ident) => { #[cfg(feature = "geo-types")] impl GeometryTrait for $geometry_type { - type T = T; - type PointType<'b> = Point where Self: 'b; - type LineStringType<'b> = LineString where Self: 'b; - type PolygonType<'b> = Polygon where Self: 'b; - type MultiPointType<'b> = MultiPoint where Self: 'b; - type MultiLineStringType<'b> = MultiLineString where Self: 'b; - type MultiPolygonType<'b> = MultiPolygon where Self: 'b; - type GeometryCollectionType<'b> = GeometryCollection where Self: 'b; - type RectType<'b> = Rect where Self: 'b; - type TriangleType<'b> = Triangle where Self: 'b; - type LineType<'b> = Line where Self: 'b; + type PointType<'b> + = Point + where + Self: 'b; + type LineStringType<'b> + = LineString + where + Self: 'b; + type PolygonType<'b> + = Polygon + where + Self: 'b; + type MultiPointType<'b> + = MultiPoint + where + Self: 'b; + type MultiLineStringType<'b> + = MultiLineString + where + Self: 'b; + type MultiPolygonType<'b> + = MultiPolygon + where + Self: 'b; + type GeometryCollectionType<'b> + = GeometryCollection + where + Self: 'b; + type RectType<'b> + = Rect + where + Self: 'b; + type TriangleType<'b> + = Triangle + where + Self: 'b; + type LineType<'b> + = Line + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -264,17 +348,46 @@ macro_rules! impl_specialization { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum + 'a> GeometryTrait for &'a $geometry_type { - type T = T; - type PointType<'b> = Point where Self: 'b; - type LineStringType<'b> = LineString where Self: 'b; - type PolygonType<'b> = Polygon where Self: 'b; - type MultiPointType<'b> = MultiPoint where Self: 'b; - type MultiLineStringType<'b> = MultiLineString where Self: 'b; - type MultiPolygonType<'b> = MultiPolygon where Self: 'b; - type GeometryCollectionType<'b> = GeometryCollection where Self: 'b; - type RectType<'b> = Rect where Self: 'b; - type TriangleType<'b> = Triangle where Self: 'b; - type LineType<'b> = Line where Self: 'b; + type PointType<'b> + = Point + where + Self: 'b; + type LineStringType<'b> + = LineString + where + Self: 'b; + type PolygonType<'b> + = Polygon + where + Self: 'b; + type MultiPointType<'b> + = MultiPoint + where + Self: 'b; + type MultiLineStringType<'b> + = MultiLineString + where + Self: 'b; + type MultiPolygonType<'b> + = MultiPolygon + where + Self: 'b; + type GeometryCollectionType<'b> + = GeometryCollection + where + Self: 'b; + type RectType<'b> + = Rect + where + Self: 'b; + type TriangleType<'b> + = Triangle + where + Self: 'b; + type LineType<'b> + = Line + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy diff --git a/geo-traits/src/geometry_collection.rs b/geo-traits/src/geometry_collection.rs index 1fc427b36..be193722c 100644 --- a/geo-traits/src/geometry_collection.rs +++ b/geo-traits/src/geometry_collection.rs @@ -7,11 +7,8 @@ use geo_types::{CoordNum, Geometry, GeometryCollection}; /// /// A GeometryCollection is a collection of [Geometry][GeometryTrait] types. pub trait GeometryCollectionTrait: Sized { - /// The coordinate type of this geometry - type T; - /// The type of each underlying geometry, which implements [GeometryTrait] - type GeometryType<'a>: 'a + GeometryTrait + type GeometryType<'a>: 'a + GeometryTrait where Self: 'a; @@ -48,8 +45,8 @@ pub trait GeometryCollectionTrait: Sized { #[cfg(feature = "geo-types")] impl GeometryCollectionTrait for GeometryCollection { - type T = T; - type GeometryType<'a> = &'a Geometry + type GeometryType<'a> + = &'a Geometry where Self: 'a; @@ -68,8 +65,9 @@ impl GeometryCollectionTrait for GeometryCollection { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum> GeometryCollectionTrait for &'a GeometryCollection { - type T = T; - type GeometryType<'b> = &'a Geometry where + type GeometryType<'b> + = &'a Geometry + where Self: 'b; fn dim(&self) -> Dimensions { diff --git a/geo-traits/src/iterator.rs b/geo-traits/src/iterator.rs index e84805462..da8c1c069 100644 --- a/geo-traits/src/iterator.rs +++ b/geo-traits/src/iterator.rs @@ -8,21 +8,16 @@ macro_rules! impl_iterator { /// An iterator over the parts of this geometry. pub(crate) struct $struct_name< 'a, - T, - $item_type: 'a + $item_trait, - G: $self_trait = $item_type>, + $item_type: 'a + $item_trait, + G: $self_trait<$item_type<'a> = $item_type>, > { geom: &'a G, index: usize, end: usize, } - impl< - 'a, - T, - $item_type: 'a + $item_trait, - G: $self_trait = $item_type>, - > $struct_name<'a, T, $item_type, G> + impl<'a, $item_type: 'a + $item_trait, G: $self_trait<$item_type<'a> = $item_type>> + $struct_name<'a, $item_type, G> { /// Create a new iterator pub fn new(geom: &'a G, index: usize, end: usize) -> Self { @@ -30,12 +25,8 @@ macro_rules! impl_iterator { } } - impl< - 'a, - T, - $item_type: 'a + $item_trait, - G: $self_trait = $item_type>, - > Iterator for $struct_name<'a, T, $item_type, G> + impl<'a, $item_type: 'a + $item_trait, G: $self_trait<$item_type<'a> = $item_type>> Iterator + for $struct_name<'a, $item_type, G> { type Item = $item_type; @@ -55,21 +46,13 @@ macro_rules! impl_iterator { } } - impl< - 'a, - T, - $item_type: 'a + $item_trait, - G: $self_trait = $item_type>, - > ExactSizeIterator for $struct_name<'a, T, $item_type, G> + impl<'a, $item_type: 'a + $item_trait, G: $self_trait<$item_type<'a> = $item_type>> + ExactSizeIterator for $struct_name<'a, $item_type, G> { } - impl< - 'a, - T, - $item_type: 'a + $item_trait, - G: $self_trait = $item_type>, - > DoubleEndedIterator for $struct_name<'a, T, $item_type, G> + impl<'a, $item_type: 'a + $item_trait, G: $self_trait<$item_type<'a> = $item_type>> + DoubleEndedIterator for $struct_name<'a, $item_type, G> { #[inline] fn next_back(&mut self) -> Option { diff --git a/geo-traits/src/line.rs b/geo-traits/src/line.rs index f8dbbf07c..e304de954 100644 --- a/geo-traits/src/line.rs +++ b/geo-traits/src/line.rs @@ -10,11 +10,8 @@ use geo_types::{Coord, CoordNum, Line}; /// /// Refer to [geo_types::Line] for information about semantics and validity. pub trait LineTrait: Sized { - /// The coordinate type of this geometry - type T; - /// The type of each underlying coordinate, which implements [CoordTrait] - type CoordType<'a>: 'a + CoordTrait + type CoordType<'a>: 'a + CoordTrait where Self: 'a; @@ -35,8 +32,10 @@ pub trait LineTrait: Sized { #[cfg(feature = "geo-types")] impl LineTrait for Line { - type T = T; - type CoordType<'a> = &'a Coord where Self: 'a; + type CoordType<'a> + = &'a Coord + where + Self: 'a; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -53,8 +52,10 @@ impl LineTrait for Line { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum> LineTrait for &'a Line { - type T = T; - type CoordType<'b> = &'a Coord where Self: 'b; + type CoordType<'b> + = &'a Coord + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -76,8 +77,10 @@ impl<'a, T: CoordNum> LineTrait for &'a Line { pub struct UnimplementedLine(PhantomData); impl LineTrait for UnimplementedLine { - type T = T; - type CoordType<'a> = UnimplementedCoord where Self: 'a; + type CoordType<'a> + = UnimplementedCoord + where + Self: 'a; fn dim(&self) -> Dimensions { unimplemented!() diff --git a/geo-traits/src/line_string.rs b/geo-traits/src/line_string.rs index ffd431c6f..95f7c2214 100644 --- a/geo-traits/src/line_string.rs +++ b/geo-traits/src/line_string.rs @@ -12,11 +12,8 @@ use geo_types::{Coord, CoordNum, LineString}; /// /// Refer to [geo_types::LineString] for information about semantics and validity. pub trait LineStringTrait: Sized { - /// The coordinate type of this geometry - type T; - /// The type of each underlying coordinate, which implements [CoordTrait] - type CoordType<'a>: 'a + CoordTrait + type CoordType<'a>: 'a + CoordTrait where Self: 'a; @@ -52,8 +49,10 @@ pub trait LineStringTrait: Sized { #[cfg(feature = "geo-types")] impl LineStringTrait for LineString { - type T = T; - type CoordType<'a> = &'a Coord where Self: 'a; + type CoordType<'a> + = &'a Coord + where + Self: 'a; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -70,8 +69,10 @@ impl LineStringTrait for LineString { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum> LineStringTrait for &'a LineString { - type T = T; - type CoordType<'b> = &'a Coord where Self: 'b; + type CoordType<'b> + = &'a Coord + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -93,8 +94,10 @@ impl<'a, T: CoordNum> LineStringTrait for &'a LineString { pub struct UnimplementedLineString(PhantomData); impl LineStringTrait for UnimplementedLineString { - type T = T; - type CoordType<'a> = UnimplementedCoord where Self: 'a; + type CoordType<'a> + = UnimplementedCoord + where + Self: 'a; fn dim(&self) -> Dimensions { unimplemented!() diff --git a/geo-traits/src/multi_line_string.rs b/geo-traits/src/multi_line_string.rs index 40296f84e..eddd879cc 100644 --- a/geo-traits/src/multi_line_string.rs +++ b/geo-traits/src/multi_line_string.rs @@ -12,11 +12,8 @@ use geo_types::{CoordNum, LineString, MultiLineString}; /// /// Refer to [geo_types::MultiLineString] for information about semantics and validity. pub trait MultiLineStringTrait: Sized { - /// The coordinate type of this geometry - type T; - /// The type of each underlying LineString, which implements [LineStringTrait] - type LineStringType<'a>: 'a + LineStringTrait + type LineStringType<'a>: 'a + LineStringTrait where Self: 'a; @@ -53,8 +50,10 @@ pub trait MultiLineStringTrait: Sized { #[cfg(feature = "geo-types")] impl MultiLineStringTrait for MultiLineString { - type T = T; - type LineStringType<'a> = &'a LineString where Self: 'a; + type LineStringType<'a> + = &'a LineString + where + Self: 'a; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -71,8 +70,10 @@ impl MultiLineStringTrait for MultiLineString { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum> MultiLineStringTrait for &'a MultiLineString { - type T = T; - type LineStringType<'b> = &'a LineString where Self: 'b; + type LineStringType<'b> + = &'a LineString + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -94,8 +95,10 @@ impl<'a, T: CoordNum> MultiLineStringTrait for &'a MultiLineString { pub struct UnimplementedMultiLineString(PhantomData); impl MultiLineStringTrait for UnimplementedMultiLineString { - type T = T; - type LineStringType<'a> = UnimplementedLineString where Self: 'a; + type LineStringType<'a> + = UnimplementedLineString + where + Self: 'a; fn dim(&self) -> Dimensions { unimplemented!() diff --git a/geo-traits/src/multi_point.rs b/geo-traits/src/multi_point.rs index 9b4f9cf12..6e92a69ba 100644 --- a/geo-traits/src/multi_point.rs +++ b/geo-traits/src/multi_point.rs @@ -11,11 +11,8 @@ use geo_types::{CoordNum, MultiPoint, Point}; /// /// Refer to [geo_types::MultiPoint] for information about semantics and validity. pub trait MultiPointTrait: Sized { - /// The coordinate type of this geometry - type T; - /// The type of each underlying Point, which implements [PointTrait] - type PointType<'a>: 'a + PointTrait + type PointType<'a>: 'a + PointTrait where Self: 'a; @@ -50,8 +47,10 @@ pub trait MultiPointTrait: Sized { #[cfg(feature = "geo-types")] impl MultiPointTrait for MultiPoint { - type T = T; - type PointType<'a> = &'a Point where Self: 'a; + type PointType<'a> + = &'a Point + where + Self: 'a; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -68,8 +67,10 @@ impl MultiPointTrait for MultiPoint { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum> MultiPointTrait for &'a MultiPoint { - type T = T; - type PointType<'b> = &'a Point where Self: 'b; + type PointType<'b> + = &'a Point + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -91,8 +92,10 @@ impl<'a, T: CoordNum> MultiPointTrait for &'a MultiPoint { pub struct UnimplementedMultiPoint(PhantomData); impl MultiPointTrait for UnimplementedMultiPoint { - type T = T; - type PointType<'a> = UnimplementedPoint where Self: 'a; + type PointType<'a> + = UnimplementedPoint + where + Self: 'a; fn dim(&self) -> Dimensions { unimplemented!() diff --git a/geo-traits/src/multi_polygon.rs b/geo-traits/src/multi_polygon.rs index a80a19368..f7dc3a45d 100644 --- a/geo-traits/src/multi_polygon.rs +++ b/geo-traits/src/multi_polygon.rs @@ -10,11 +10,8 @@ use geo_types::{CoordNum, MultiPolygon, Polygon}; /// /// Refer to [geo_types::MultiPolygon] for information about semantics and validity. pub trait MultiPolygonTrait: Sized { - /// The coordinate type of this geometry - type T; - /// The type of each underlying Polygon, which implements [PolygonTrait] - type PolygonType<'a>: 'a + PolygonTrait + type PolygonType<'a>: 'a + PolygonTrait where Self: 'a; @@ -51,8 +48,10 @@ pub trait MultiPolygonTrait: Sized { #[cfg(feature = "geo-types")] impl MultiPolygonTrait for MultiPolygon { - type T = T; - type PolygonType<'a> = &'a Polygon where Self: 'a; + type PolygonType<'a> + = &'a Polygon + where + Self: 'a; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -69,8 +68,10 @@ impl MultiPolygonTrait for MultiPolygon { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum> MultiPolygonTrait for &'a MultiPolygon { - type T = T; - type PolygonType<'b> = &'a Polygon where Self: 'b; + type PolygonType<'b> + = &'a Polygon + where + Self: 'b; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -92,8 +93,10 @@ impl<'a, T: CoordNum> MultiPolygonTrait for &'a MultiPolygon { pub struct UnimplementedMultiPolygon(PhantomData); impl MultiPolygonTrait for UnimplementedMultiPolygon { - type T = T; - type PolygonType<'a> = UnimplementedPolygon where Self: 'a; + type PolygonType<'a> + = UnimplementedPolygon + where + Self: 'a; fn dim(&self) -> Dimensions { unimplemented!() diff --git a/geo-traits/src/polygon.rs b/geo-traits/src/polygon.rs index 203a7cee5..8963734f9 100644 --- a/geo-traits/src/polygon.rs +++ b/geo-traits/src/polygon.rs @@ -14,11 +14,8 @@ use geo_types::{CoordNum, LineString, Polygon}; /// /// Refer to [geo_types::Polygon] for information about semantics and validity. pub trait PolygonTrait: Sized { - /// The coordinate type of this geometry - type T; - /// The type of each underlying ring, which implements [LineStringTrait] - type RingType<'a>: 'a + LineStringTrait + type RingType<'a>: 'a + LineStringTrait where Self: 'a; @@ -56,8 +53,10 @@ pub trait PolygonTrait: Sized { #[cfg(feature = "geo-types")] impl PolygonTrait for Polygon { - type T = T; - type RingType<'a> = &'a LineString where Self: 'a; + type RingType<'a> + = &'a LineString + where + Self: 'a; fn dim(&self) -> Dimensions { Dimensions::Xy @@ -83,8 +82,9 @@ impl PolygonTrait for Polygon { #[cfg(feature = "geo-types")] impl<'a, T: CoordNum> PolygonTrait for &'a Polygon { - type T = T; - type RingType<'b> = &'a LineString where + type RingType<'b> + = &'a LineString + where Self: 'b; fn dim(&self) -> Dimensions { @@ -116,8 +116,10 @@ impl<'a, T: CoordNum> PolygonTrait for &'a Polygon { pub struct UnimplementedPolygon(PhantomData); impl PolygonTrait for UnimplementedPolygon { - type T = T; - type RingType<'a> = UnimplementedLineString where Self: 'a; + type RingType<'a> + = UnimplementedLineString + where + Self: 'a; fn dim(&self) -> Dimensions { unimplemented!()