首页 > 解决方案 > 在 Rust 的范围内找不到包含的 Trait 实现的方法

问题描述

我想使用两个外部库(geo-types-0.6.0 和 geo-offset-0.1.0)来执行几何算法。

下面的例子看起来不错:Line类型是在 library 中定义的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)?;

标签: rustcompiler-errors

解决方案


geo-offsetcrate 实现了for的Offsettrait geo::Line,而不是geo_types::Line( src - search for geo::Line)。所以即便如此geo::Line只是对.geo_types::LineOffsetgeo::Line


推荐阅读