Method from included Trait implementation not found in scope in Rust

Viewed 426

I want to use two external libraries (geo-types-0.6.0 and geo-offset-0.1.0) to perform geometric algorithms.

The example below seems fine: The Line type is defined in the library geo_types. The Offset trait moreover is written in geo_offset. Including this trait should lead to the Line type implementing method offset. However I get the following error:

no method named `offset` found for struct `geo_types::line::Line<float>` in the current scope

In addition to that, the rust-analyzer in VS Code tells me, that the included trait Offset is not used. Why is that?

use geo_types::{Coordinate, Line};
use geo_offset::Offset;

let line = Line::new(
    Coordinate { x: 0.0, y: 0.0 },
    Coordinate { x: 1.0, y: 8.0 },
);

let line_with_offset = line.offset(2.0)?;
1 Answers

The geo-offset crate implements the Offset trait for geo::Line, not geo_types::Line (src - search for geo::Line). So even so geo::Line is just a re-export of geo_types::Line, the rust compiler doesn't see this deep and only knows about the Offset implementation for geo::Line.

Related