How do I print variables in Rust and have it show everything about that variable, like Ruby's .inspect?

后端 未结 2 1108
梦谈多话
梦谈多话 2021-02-13 03:56
use std::collections::HashMap;

fn main() {
    let mut hash = HashMap::new();
    hash.insert(\"Daniel\", \"798-1364\");
    println!(\"{}\", hash);
}

2条回答
  •  天涯浪人
    2021-02-13 04:41

    Rust 1.32 introduced the dbg macro:

    use std::collections::HashMap;
    
    fn main() {
        let mut hash = HashMap::new();
        hash.insert("Daniel", "798-1364");
        dbg!(hash);
    }
    

    This will print:

    [src/main.rs:6] hash = {
        "Daniel": "798-1364"
    }
    

提交回复
热议问题