Rust 未解析的导入:“std::num”中没有“atan”`

Rust 未解析的导入:“std::num”中没有“atan”`,rust,Rust,我正在构建Rust教程中的示例。当我尝试编译此示例时: use std::float; use std::num::atan; fn angle(vector: (float, float)) -> float { let pi = float::consts::pi; match vector { (0f, y) if y < 0f => 1.5 * pi, (0f, y) => 0.5 * pi, (x, y) =&

我正在构建Rust教程中的示例。当我尝试编译此示例时:

use std::float;
use std::num::atan;
fn angle(vector: (float, float)) -> float {
    let pi = float::consts::pi;
    match vector {
      (0f, y) if y < 0f => 1.5 * pi,
      (0f, y) => 0.5 * pi,
      (x, y) => atan(y / x)
    }
}
使用std::float;
使用std::num::atan;
fn角度(矢量:(浮点,浮点))->浮点{
设pi=float::consts::pi;
匹配向量{
(0f,y)如果y<0f=>1.5*pi,
(0f,y)=>0.5*pi,
(x,y)=>atan(y/x)
}
}

我犯了名义上的错误。我正在使用
rust build Test.rs
进行编译。为什么编译器找不到
std::num::atan

函数
atan
不是
std::num
的成员,因为它被定义为
impl
的一部分。但是,以下措施将起作用:

use std::float;

fn angle(vector: (float, float)) -> float {
    let pi = float::consts::pi;
    match vector {
      (0f, y) if y < 0f => 1.5 * pi,
      (0f, y) => 0.5 * pi,
      (x, y) => (y / x).atan()
    }
}
使用std::float;
fn角度(矢量:(浮点,浮点))->浮点{
设pi=float::consts::pi;
匹配向量{
(0f,y)如果y<0f=>1.5*pi,
(0f,y)=>0.5*pi,
(x,y)=>(y/x).atan()
}
}
这是因为
atan
trigonal
的成员,而
float
实现了该功能


我认为,做出这个决定的原因是Rust中没有重载,因此为了将函数名应用于多个具体类型,它必须是特性的一部分。在这种情况下,
三角
是一种数值特征,它允许对
int
float
f64
等方法进行多种实现。

您使用的是哪种版本的rust?0.7? 0.8-pre?我用的是0.7。我也在Windows上。教程过时了吗?另外,哪里是问Rust问题的最佳地方?Rust仍在积极开发中(主要版本<1),因此代码/文档大量流失,而且事情并不总是正确的。也有可能您看到了一个过时的文档(我不小心读了0.2个文档)。你在哪里看到了这方面的文档?这个例子使用了有问题的导入。这看起来像是文档中的一个bug。我已经向主分支提交了一个pull请求:对不起,它看起来像是在0.8中向前推进,
std::num
中有一个名为
atan
的函数,但它不能在0.7中实现。