How to introspect all available methods and members of a Rust type?

前端 未结 6 611
心在旅途
心在旅途 2020-12-11 00:33

Is there a way to print out a complete list of available members of a type or instance in Rust?

For example:

  • In Python, I can use print(dir(objec
6条回答
  •  清歌不尽
    2020-12-11 01:19

    I use something like this:

    println!("{:?}", variable); // struct, enum whatever
    

    If it's a large type, use the # version:

    println!("{:#?}", variable); // struct, enum whatever
    

提交回复
热议问题