4 releases

0.0.4 Sep 15, 2021
0.0.3 Sep 15, 2021
0.0.2 Sep 15, 2021
0.0.1 Sep 14, 2021
0.0.1-patch-readme Sep 15, 2021

#82 in #description

Download history 59/week @ 2024-05-06 142/week @ 2024-05-13 163/week @ 2024-05-20 186/week @ 2024-05-27 177/week @ 2024-06-03 137/week @ 2024-06-10 207/week @ 2024-06-17 172/week @ 2024-06-24 137/week @ 2024-07-01 162/week @ 2024-07-08 141/week @ 2024-07-15 103/week @ 2024-07-22 148/week @ 2024-07-29 152/week @ 2024-08-05 39/week @ 2024-08-12 105/week @ 2024-08-19

448 downloads per month

Apache-2.0

34KB
432 lines

Simple Struct Descriptor

Crates.io Crates.io License Build Status Coverage Status

Easy pretty print your Rust struct into single element or table

Example

use descriptor::{object_describe_to_string, table_describe_to_string, Descriptor};

#[derive(Descriptor)]
struct User {
    name: String,
    age: i32,
    address: Address,
}

#[derive(Descriptor)]
struct Address {
    street: String,
    town: String,
}

fn main() {
    let user1 = User {
        name: "Adrien".to_string(),
        age: 32,
        address: Address {
            street: "Main street".to_string(),
            town: "NY".to_string()
        }
    };
    let user2 = User {
        name: "Corentin".to_string(),
        age: 40,
        address: Address {
            street: "10 rue de la paix".to_string(),
            town: "Paris".to_string()
        }
    };
    let description = object_describe_to_string(&user1).unwrap();

    assert_eq!(r#"
     Name:    Adrien
     Age:     32
     Address:
       Street: Main street
       Town:   NY
     "#, description);

    let table = table_describe_to_string(&vec![user1, user2]).unwrap();

    assert_eq!(r#"
     NAME     AGE ADDRESS.STREET    ADDRESS.TOWN
     Adrien   32  Main street       NY
     Corentin 40  10 rue de la paix Paris
     "#, format!("\n{}", table));
}

Dependencies

~1.5MB
~40K SLoC