Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no method named union found #22

Open
inclooder opened this issue Apr 26, 2020 · 5 comments
Open

no method named union found #22

inclooder opened this issue Apr 26, 2020 · 5 comments

Comments

@inclooder
Copy link

I'm getting this error. I've tried both 0.2.1 and 0.1.4

warning: unused imports: `GeoJson`, `Value`
 --> src/main.rs:2:15
  |
2 | use geojson::{GeoJson, Value};
  |               ^^^^^^^  ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0599]: no method named `union` found for struct `geo_types::polygon::Polygon<{float}>` in the current scope
  --> src/main.rs:21:23
   |
21 |     let union = poly1.union(&poly2);
   |                       ^^^^^ method not found in `geo_types::polygon::Polygon<{float}>`

warning: unused import: `geo_booleanop::boolean::BooleanOp`
 --> src/main.rs:3:5
  |
3 | use geo_booleanop::boolean::BooleanOp;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `geo-test-rust`.

To learn more, run the command again with --verbose.

Clone and build this repo to reproduce https://github.com/inclooder/rust-geo-test

@bluenote10
Copy link
Contributor

bluenote10 commented Apr 26, 2020

Looks like you need to use geo-types = "0.4.0" for now.

As mentioned in #16, we may have to make a few adjustments for version 0.5.x.

But to be honest, it is not immediately clear to me what exactly it is that has changed in geo-types that causes this compiler error.

image

It is confusing that cargo says it can compile geo-booleanop v0.2.1 when using geo-types v0.5.0. I would assume that it simply cannot compile it, because of the breaking change in the Rect type.

To the Rust experts: Does Rust swallow the compile error because everything is generic? Is there a way to make such problems more explicit?

@inclooder
Copy link
Author

inclooder commented Apr 27, 2020

I'm new to rust but maybe something like "^0.4" could work to prevent the lib from compiling with newer versions?
I've found it here https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#caret-requirements

I've made it compile by changing geo-types version as you suggested but I also had to downgrade geo & geojson versions...

@inclooder
Copy link
Author

I'm new to rust but maybe something like "^0.4" could work to prevent the lib from compiling with newer versions?

2020-04-27_16-49
Should work anyway based on this statement 🤔

@bluenote10
Copy link
Contributor

FYI I have asked a question about that on SO. It looks like this is a weak point in cargo's dependency handling when extending a base type with an addon trait, expressed by the sarcastic comment:

Your error this time is actually one of the more readable ones.

@caewok
Copy link

caewok commented Mar 21, 2022

I ran into this issue when trying to use the 0.7 branch of geo-types. Basically, geo-types 0.6.2 works with booleanop 0.3.2. And geo-types 0.4.0 works with booleanop 0.2.2. Specifying other combinations fails with same error as the OP about no method named "union" and unused BooleanOp import.

Per this SO, I think I have a work-around.

Assume you want to use the 0.7 branch of geo-types, either directly or because some other crate depends on it. In the Cargo.toml, alias the older 0.6 branch, and then use that alias explicitly when you want to use booleanop.

Cargo.toml:

old-geo-types = { package = "geo-types", version = "0.6.2" }
geo-types = "0.7.3"
geo-booleanop = "0.3.2"

Rust code:

use old_geo_types::{Polygon, polygon};
use geo_booleanop::boolean::BooleanOp;

fn main() {
    let big: Polygon<f64> = polygon![
        (x: 416., y: 256.),
        (x: 432., y: 240.),
        (x: 432., y: 224.),
        (x: 448., y: 280.),
        (x: 480., y: 208.),
        (x: 480., y: 256.),
    ];

    let small: Polygon<f64>  = polygon![
        (x: 400., y: 272.),
        (x: 416., y: 256.),
        (x: 480., y: 256.),
        (x: 480., y: 272.),
    ];

    let union = small.union(&big);
    for p in union.into_iter() {
        dbg!(p);
    }
}

This seems to work, assuming:

  1. You don't need to rely on the newer geo-types where you are running booleanop code. So you presumably could create a geo-types 0.7 Polygon in the same code, so long as you don't need to call, e.g., union on it and you specify which crate you are using. (geo_types::Polygon versus old_geo_types::Polygon)
  2. You alias an older major version. Aliasing 0.7 and then separately importing 0.7.3 for geo-types makes the compiler mad.

This seems easier than recompiling booleanop to work with newer versions of geo-types! Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants