如何从数字中解析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"我所做的似乎与本文档中的内容相符, 也是本文档 ,也是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"));I am trying to use BigInt. My code is like this:
extern crate num; use num::bigint::BigInt; ... println!("{}", from_str::<BigInt>("1")); //this is line 91 in the codeIn my Cargo.toml file I have the following:
[dependencies] num = "0.1.30"What I did seem to match what was said in this document, also this document and also an answer here on Stack Overflow.
However I got the following error:
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) => { ...Figured out, seem like the current syntax is:
"8705702225074732811211966512111".parse::<BigInt>().unwrap();Better yet, do the following:
match "8705702225074732811211966512111".parse::<BigInt>() { Ok(big) => { ...更多推荐
发布评论