如何从 num crate 解析 BigInt?
How to parse BigInt from the num crate?
我正在尝试使用 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 document, also this document and also an 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"));
明白了,目前的语法似乎是:
"8705702225074732811211966512111".parse::<BigInt>().unwrap();
更好的是,执行以下操作:
match "8705702225074732811211966512111".parse::<BigInt>() {
Ok(big) => {
...
我正在尝试使用 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 document, also this document and also an 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"));
明白了,目前的语法似乎是:
"8705702225074732811211966512111".parse::<BigInt>().unwrap();
更好的是,执行以下操作:
match "8705702225074732811211966512111".parse::<BigInt>() {
Ok(big) => {
...