【发布时间】:2014-10-07 13:37:48
【问题描述】:
我在玩 cgmath 库。我有以下 main.rs 文件:
extern crate cgmath;
use cgmath::vector::{Vector3, EuclideanVector};
fn main() {
let mypoint = Vector3 { x: 1f64, y: 1f64, z: 3f64 };
println!("The length of the vector is {}, and the length squared is {}", mypoint.length(), mypoint.length2());
}
在我的使用行中,当我省略EuclideanVector 时,出现以下编译错误:
type 'cgmath::vector::Vector3<f64>' does not implement any method in scope named 'length'
除非我导入 Vector3 使用的特征之一,否则 Rust 编译器似乎找不到 length() 方法。深入研究source code,看起来长度方法是在EuclideanVector trait 中定义的。
直观地说,我不需要导入特征来使用继承所述特征的类型。有没有一种技术可以让我失踪?这是 cgmath 库特有的细微差别吗?这是我应该习惯的 Rust 的惯用部分吗?
【问题讨论】:
标签: rust