如何从数字中解析BigInt?(How to parse BigInt from the num crate?)

编程入门 行业动态 更新时间:2024-10-25 08:25:42
如何从数字中解析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 code

In 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) => { ...

更多推荐

本文发布于:2023-08-07 08:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1461576.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数字   BigInt   parse   num   crate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!