Skip to content

try_into() not working: the trait bound geos::Geometry<'_>: From<&geo_types::MultiPolygon<f64>> is not satisfied #90

@velvia

Description

@velvia

I must be doing something dumb.

Rust 2018 edition, Geos v8.0.1

Code:

use geo::{MultiPolygon};
use std::convert::TryInto;
use geos::{Geometry as GGeometry};

#[derive(Clone, Debug)]
pub struct GeomAndId {
    pub geom: MultiPolygon<f64>,
    pub id: u128,  // TODO: use core.Id etc.
}

impl GeomAndId {
    pub fn geos_geom(&self) -> Result<GGeometry<'static>, StringError> {
        let g: GGeometry = (&self.geom).try_into().map_err(|e| {
            format!("Geometry could not be converted to GEOS: {}", e).into()
        })?;
        Ok(g)
    }
}

Error:

error[E0277]: the trait bound `geos::Geometry<'_>: From<&geo_types::MultiPolygon<f64>>` is not satisfied
  --> geo.rs:20:41
   |
20 |         let g: GGeometry = (&self.geom).try_into().map_err(|e| {
   |                                         ^^^^^^^^ the trait `From<&geo_types::MultiPolygon<f64>>` is not implemented for `geos::Geometry<'_>`
   |
   = note: required because of the requirements on the impl of `Into<geos::Geometry<'_>>` for `&geo_types::MultiPolygon<f64>`
   = note: required because of the requirements on the impl of `TryFrom<&geo_types::MultiPolygon<f64>>` for `geos::Geometry<'_>`
   = note: required because of the requirements on the impl of `TryInto<geos::Geometry<'_>>` for `&geo_types::MultiPolygon<f64>`

It seems like somehow using try_into() is causing it to want the From trait, but clearly according to docs, the Geos TryFrom<&'a MultiPolygon<f64> trait exists, so what gives? Any help appreciated, thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions