GDAL crate defines traits for foreign types -- how?

The Rust book chapter 10.2 reads:

One restriction to note with trait implementations is that we can implement a trait on a type only if either the trait or the type is local to our crate. For example, we can implement standard library traits like Display on a custom type like Tweet as part of our aggregator crate functionality, because the type Tweet is local to our aggregator crate. We can also implement Summary on Vec<T> in our aggregator crate, because the trait Summary is local to our aggregator crate.

But here, I see a trait defined for an imported type:

use geo_types::CoordFloat;

impl<T> ToGdal for geo_types::LineString<T>
where
    T: CoordFloat,
{
    fn to_gdal(&self) -> Result<Geometry> {
        geometry_with_points(OGRwkbGeometryType::wkbLineString, self)
    }
}

Why does this module address something from geo_types while geo_types isn't use-d?

Cargo.toml in that package:

[dependencies]
geo-types = { version = "0.7" }

Why is it possible to implement a type on a trait, while both are from foreign crates?

The ToGdal trait is defined in the same crate, so it is not foreign.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.