geo
geo copied to clipboard
Borrowed rstar CachedEnvelope container results in un-ergonomic code
trafficstars
I was moving some geometries into a CachedEnvelope, and while fixing up the types found the following:
let p1: Point = (0., 1.).into();
let ce = CachedEnvelope::new(p1);
let bce = &ce; // pretend we're getting this out of a lending iterator
let p2: Point = (1., 1.).into();
p2.intersects(bce); // doesn't work
p2.intersects(*bce); // doesn't work
p2.intersects(**bce); // doesn't work
p2.intersects(&**bce); // FINALLY but look at that
Rust-Analyzer wasn't helpful here (which is fine) – you just "have to know" that you have to double-deref and then borrow again. Lots of people don't even know that you can double-deref.
Error messages in same order as above
error[E0277]: the trait bound `geo_types::Line<T>: algorithm::intersects::Intersects<CachedEnvelope<geo_types::Line<T>>>` is not satisfied
--> geo/src/algorithm/simplify_vw.rs:429:39
|
429 | && new_segment.intersects(candidate)
| ---------- ^^^^^^^^^ the trait `algorithm::intersects::Intersects<CachedEnvelope<geo_types::Line<T>>>` is not implemented for `geo_types::Line<T>`
| |
| required by a bound introduced by this call
error[E0308]: mismatched types
--> geo/src/algorithm/simplify_vw.rs:429:39
|
429 | && new_segment.intersects(*candidate)
| ---------- ^^^^^^^^^^ expected `&_`, found `CachedEnvelope<Line<T>>`
| |
| arguments to this method are incorrect
|
= note: expected reference `&_`
found struct `CachedEnvelope<geo_types::Line<T>>`
error[E0308]: mismatched types
--> geo/src/algorithm/simplify_vw.rs:429:39
|
429 | && new_segment.intersects(**candidate)
| ---------- ^^^^^^^^^^^ expected `&_`, found `Line<T>`
| |
| arguments to this method are incorrect
Anyway, I'm not sure what we can do about this – CachedEnvelope already impls Deref.