Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rust 如何从类型别名使用原始类型的方法?_Rust_Rust 0.11 - Fatal编程技术网

Rust 如何从类型别名使用原始类型的方法?

Rust 如何从类型别名使用原始类型的方法?,rust,rust-0.11,Rust,Rust 0.11,这个问题可能有点抽象,但我有一个相当简单的例子: extern crate num; use num::rational::Rational; fn doit() -> Rational { Rational::new_raw(3, 5) } 我得到了一个错误: 134:42 error: unresolved name `Rational::new_raw`. fn doit() -> Rational { Rational::new_raw(3, 5) }

这个问题可能有点抽象,但我有一个相当简单的例子:

extern crate num;

use num::rational::Rational;

fn doit() -> Rational { Rational::new_raw(3, 5) }
我得到了一个错误:

134:42 error: unresolved name `Rational::new_raw`.
fn doit() -> Rational { Rational::new_raw(3, 5) }
                        ^~~~~~~~~~~~~~~~~
因此,错误不在
Rational
本身(很好地导入,其他地方没有问题),而是在尝试使用
Rational::new\u raw
时。现在,从我们得到的文档中:

type Rational = Ratio<int>;

有没有合适的方法来实现这一点,或者这被认为是一个bug?

这是(大部分)目前的预期行为:
type
实际上只是一个类型的别名,不允许调用静态方法。问题并涵盖此问题。

可能与此bug有关:@CyrilleKa:看起来确实相关;显然别名不是完整的公民:x
impl<T: Clone + Integer + Ord> Ratio<T> {
    fn new_raw(numer: T, denom: T) -> Ratio<T>;
    // ...
}
fn doit() -> Rational { Ratio::<int>::new_raw(3, 5) }
$ rustc --version
rustc 0.11.0-pre-nightly (022a7b3 2014-05-22 01:06:25 -0700)
host: x86_64-unknown-linux-gnu