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"));
There are the following different ways we can convert BigInt to numeric values. Number constructor accepts object type and returns number data. the constructor takes bigint data and returns numbers. Following is an example for parse bigint to number. parseInt () method parses and object returns numeric value.
A BigInt is a combination of BigUint and Sign. Common numerical operations are overloaded, so we can treat them the same way we treat other numbers. See the “Features” section for instructions for enabling random number generation.
There are the following different ways we can convert BigInt to numeric values. Number constructor accepts object type and returns number data. the constructor takes bigint data and returns numbers. Following is an example for parse bigint to number. parseInt () method parses and object returns numeric value. The same above works in typescript.
A BigInt is a combination of BigUint and Sign. Common numerical operations are overloaded, so we can treat them the same way we treat other numbers. See the “Features” section for instructions for enabling random number generation. The std crate feature is enabled by default, and is mandatory before Rust 1.36 and the stabilized alloc crate.
Figured out, seem like the current syntax is:
"8705702225074732811211966512111".parse::<BigInt>().unwrap();
Better yet, do the following:
match "8705702225074732811211966512111".parse::<BigInt>() {
Ok(big) => {
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With