2016-01-12 40 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