[英]Method from included Trait implementation not found in scope in Rust
I want to use two external libraries (geo-types-0.6.0 and geo-offset-0.1.0) to perform geometric algorithms.我想使用两个外部库(geo-types-0.6.0 和 geo-offset-0.1.0)来执行几何算法。
The example below seems fine: The Line
type is defined in the library geo_types
.下面的示例看起来不错: Line
类型在库geo_types
定义。 The Offset
trait moreover is written in geo_offset
.此外, Offset
特征写在geo_offset
。 Including this trait should lead to the Line
type implementing method offset
.包含这个特性应该会导致Line
类型实现方法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.除此之外,VS Code 中的rust-analyzer
告诉我,未使用包含的 trait Offset
。 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)?;
The geo-offset
crate implements the Offset
trait for geo::Line
, not geo_types::Line
( src - search for geo::Line
). geo-offset
crate 实现了geo::Line
的Offset
trait,而不是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
.所以即使这样geo::Line
只是geo_types::Line
的重新导出, geo_types::Line
编译器不会看到这么深,只知道geo::Line
的Offset
实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.