2016-01-12 42 views
4

我正在尝试使用BigInt。我的代码是这样的:如何从数据包中解析BigInt?

extern crate num; 
use num::bigint::BigInt; 
... 
println!("{}", from_str::<BigInt>("1")); //this is line 91 in the code 

在我Cargo.toml文件我有以下几点:

[dependencies] 
num = "0.1.30" 

我似乎以匹配在this documentalso this documentan answer here on Stack Overflow说。

不过,我得到了以下错误:

Compiling example v0.1.0 (file:///C:/src/rust/example) 
src\main.rs:91:20: 91:38 error: unresolved name `from_str` [E0425] 
src\main.rs:91  println!("{}", from_str::<BigInt>("1")); 

回答

4

想通了,似乎是目前的语法是:

"8705702225074732811211966512111".parse::<BigInt>().unwrap(); 

更重要的是,请执行下列操作:

match "8705702225074732811211966512111".parse::<BigInt>() { 
    Ok(big) => { 
     ... 
+0

只是为了清楚地说明:所有使用'from_str'的​​例子都过时了,这个函数已经被删除了,并且支持'.parse'。 – kirelagin