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

Borrowed rstar CachedEnvelope container results in un-ergonomic code #1086

Open
urschrei opened this issue Oct 9, 2023 · 0 comments
Open

Comments

@urschrei
Copy link
Member

urschrei commented Oct 9, 2023

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.

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

1 participant