rust - 在 Rust 的范围内找不到来自包含的 Trait 实现的方法

标签 rust compiler-errors

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

下面的例子看起来不错: Line类型在库中定义 geo_types . Offset trait 还写在 geo_offset 中.包括这个特征应该导致 Line类型实现方法offset . 但是我收到以下错误:

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

除此之外,rust-analyzer在 VS Code 中告诉我,包含的特征 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 crate 实现了 geo::LineOffset 特性,而不是 geo_types::Line(src - 搜索 geo::Line)。所以即便如此,geo::Line 只是 geo_types::Line 的重新导出,rust 编译器看不到这么深,只知道 geo::Line 的偏移量 实现。

关于rust - 在 Rust 的范围内找不到来自包含的 Trait 实现的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63843133/

相关文章:

rust - 我可以创建类型为 `Option<&str>` 的绑定(bind)吗?

enums - 为特定变体派生特征

plot - Tradingview Pine Script plotshape函数不适用于条件序列-错误在哪里?

c++ - 无法打开Watcom错误(wpp): No such file or directory*

static_cast< > 中的 C++ 编译错误

rust - 如何解析基于 LLVM MCJIT 的 JIT 中的当前进程符号?

rust - 将字符串写入文件

generics - 使用泛型进行算术运算时不能应用二元运算

forms - VBA Access 编译错误-找不到数据成员-如何忽略?

c++ - Eclipse CDT 编译错误