miracl / core

MIRACL Core
Apache License 2.0
199 stars 68 forks source link

Implemment Debug, Display #31

Closed bitdivine closed 3 years ago

bitdivine commented 3 years ago

Motivation

Rust has standard methods for formatting structures. The advantage of using the standard methods that I am most interested in is that composite structures containing Miracl structures don't need to implement custom formatting. With this PR, this becomes possible:

#[derive(Display, Debug)]
struct MyComposite {
  big:  BIG,
  ecp: ECP,
  ecp2: ECP2,
}

#[test]
fn can_print() {
    let my_composite = MyComposite { big: BIG::new(), ecp: ECP::new(), ecp2: ECP2::new() };
    println!("Display output: {}", &my_composite);
    println!("Compact debug output: {:?}", &my_composite);
    println!("Pretty debug output: {:#?}", &my_composite);
}