Trait RTree::Point not implemented for a struct, though it is

RStar can create RTree index on any structure that implements RTreeObject.

Here's a piece of module, and it compiles correctly inside the crate where it sits:

use geo::{Point, LineString};
use rstar::{RTreeObject, AABB, RTree};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LeapEdge {
	pub geom: LineString<f32>,
}

impl RTreeObject for LeapEdge {
	type Envelope = AABB<Point<f32>>;
	fn envelope(&self) -> Self::Envelope {
		self.geom.envelope()
	}
}

pub struct MyIndex {
    rtree: RTree<LeapEdge>
}

But when I try to import LeapEdge and declare RTree<LeapEdge> in another crate, it is imported correctly, but fails to compile:

use crate1::leap::LeapEdge;

pub struct MyIndex {
    rtree: RTree<LeapEdge>
}

Error:

    rtree: RTree<LeapEdge>
           ^^^^^^^^^^^^^^^ the trait `Point` is not implemented for `LeapEdge`

(trait Point is rstar::Point)

Importing all possible traits from rtstar didn't help.

What am I doing wrong?

The error message looks pretty clear to me, you are not implementing the trait Point. In the code you posted above I can only see an implementation of RTreeObject for LeadEdge, not Point.

When I tried adding that implementation in the crate #1, the error message was "conflicting implementations of trait Point".

So, now when I keep everything in crate 1 and have functions that instantiate objects there, everything works -- not just compiles, but creates an new RTree in crate 2.

error[E0119]: conflicting implementations of trait `RTreeObject` for type `LeapEdge`
  --> src/leap.rs:26:1
   |
26 | impl RTreeObject for LeapEdge {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: conflicting implementation in crate `rstar`:
           - impl<P> RTreeObject for P
             where P: rstar::Point;

I think it's blanket implementation.

: deleted former response/query - sorry, i quickly skimmed through and didn't notice you talk about published crates...

This is saying that RTreeObject is automatically implemented for any type that implements Point. So if you implemented Point you can't and don't need to implement RTreeObject for your type.

I found what was wrong: two crates had different versions of rstar and geo. One had geo=0.25 & rstar=0.10, another one had 0.25 & 0.11, and there's a bug with rstar updates being imcompatible with geo versions.

If anyone runs into this, here's the Github ticket.

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.