我想使用两个外部库(geo-types-0.6.0 和 geo-offset-0.1.0)来执行几何算法。
下面的例子看起来不错:
Line
类型在库 geo_types
中定义。
此外,Offset
特征还写在 geo_offset
中。包含这个特征应该会导致Line
类型的实现方法offset
。
但是我收到以下错误:
no method named `offset` found for struct `geo_types::line::Line<float>` in the current scope
除此之外,VS Code 中的
rust-analyzer
告诉我,包含的特征 Offset
没有被使用。这是为什么?
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)?;
geo-offset
板条箱实现了 Offset
的 geo::Line
特征,而不是 geo_types::Line
(src - 搜索 geo::Line
)。因此,即使 geo::Line
只是 geo_types::Line
的重新导出,Rust 编译器也看不到这么深,只知道 Offset
的 geo::Line
实现。