Macro geo::geometry_delegate_impl [−][src]
Implements the common pattern where a Geometry enum simply delegates its trait impl to it’s inner type.
e.g.
trait Foo<T: GeoNum> { fn foo_1(&self, coord: Coordinate<T>) -> bool; fn foo_2(&self) -> i32; } // Assuming we have an impl for all the inner types like this: impl<T: GeoNum> Foo<T> for Point<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { true } fn foo_2(&self) -> i32 { 3 } } impl<T: GeoNum> Foo<T> for LineString<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { true } fn foo_2(&self) -> i32 { 9 } } impl<T: GeoNum> Foo<T> for Line<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { true } fn foo_2(&self) -> i32 { 8 } } impl<T: GeoNum> Foo<T> for Rect<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { true } fn foo_2(&self) -> i32 { 7 } } impl<T: GeoNum> Foo<T> for Triangle<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { true } fn foo_2(&self) -> i32 { 6 } } impl<T: GeoNum> Foo<T> for Polygon<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { true } fn foo_2(&self) -> i32 { 5 } } impl<T: GeoNum> Foo<T> for MultiPoint<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { false } fn foo_2(&self) -> i32 { 4 } } impl<T: GeoNum> Foo<T> for MultiPolygon<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { false } fn foo_2(&self) -> i32 { 3 } } impl<T: GeoNum> Foo<T> for GeometryCollection<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { false } fn foo_2(&self) -> i32 { 2 } } impl<T: GeoNum> Foo<T> for MultiLineString<T> { fn foo_1(&self, coord: Coordinate<T>) -> bool { false } fn foo_2(&self) -> i32 { 1 } } // If we want the impl for Geometry to simply delegate to it's // inner case... impl<T: GeoNum> Foo<T> for Geometry<T> { // Instead of writing out this trivial enum delegation... // fn foo_1(&self, coord: Coordinate<T>) -> bool { // match self { // Geometry::Point(g) => g.foo_1(coord), // Geometry::LineString(g) => g.foo_1(coord), // _ => todo!("...etc for other cases") // } // } // // fn foo_2(&self) -> i32 { // match self { // Geometry::Point(g) => g.foo_2(), // Geometry::LineString(g) => g.foo_2(), // _ => todo!("...etc for other cases") // } // } // we can equivalently write: geo::geometry_delegate_impl! { fn foo_1(&self, coord: Coordinate<T>) -> bool; fn foo_2(&self) -> i32; } }