Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This
From
impl doesnt give us much and causes awkwardness downstream.
As with most blanket implementations, the problems are little convoluted to explain, but I hit this while working on the WKT crate. Here's an example of the kind of thing I was trying to do but can't (without jumping through some hoops): ``` trait FromSerialized<T> { fn from_serialized(serialized: &str) -> Self; } impl<T: CoordNum, IG> FromSerialized<T> for IG where IG: TryFrom<Geometry<T>> + Into<Geometry<T>> + Default { fn from_serialized(serialized: &str) -> Self { let g: Geometry<T> = parse_geometry(serialized); let specific = Self::try_from(g).map_err(|_| "Got Foo, expected Bar").unwrap(); specific } } fn parse_geometry<T: CoordNum>(_serialized: &str) -> Geometry<T> { todo!("pretend this does something interesting, like parsing WKT") } mod tests { use crate::{Point, GeometryCollection}; use super::{FromSerialized}; #[test] fn example() { // All geometries *except* GeometryCollections will compile let point: Point<f64> = Point::from_serialized("asdf"); // But GeometryCollection cannot compile! // It has no `impl TryFrom<Geometry>`, because such an impl would conflict with the existing // (now deprecated) `impl TryFrom<Into<Geometry>> for GeometryCollection` let geom_collection: GeometryCollection<f64> = GeometryCollection::from_serialized("asdf"); } } ``` I think it'll be possible to work around it in the WKT crate, but it'll be a little awkward, and I don't think we're getting much mileage out of this impl. If people are commonly creating GeometryCollections from a single geometry, I think something like `GeometryCollection::from_one(point)` (or whatever) would be less obtrusive.
- Loading branch information