In Rust, how do I use implemented trait FromStr on BigInt?

前端 未结 4 1381
长情又很酷
长情又很酷 2020-12-19 17:03

I am trying to get this program to compile:

extern crate num;
use num::bigint::BigInt;
use std::from_str::FromStr;

fn main () {
    println!(\"{}\", BigInt:         


        
4条回答
  •  青春惊慌失措
    2020-12-19 17:28

    The plain function from_str has been removed in recent versions of Rust. This function is now only available as a method of the FromStr trait.

    The modern way to parse values is the .parse method of str:

    extern crate num;
    use num::bigint::BigInt;
    
    fn main() {
        match "1".parse::() {
            Ok(n)  => println!("{}", n),
            Err(_) => println!("Error")
        }
    }
    

提交回复
热议问题