3 releases

0.0.4 Sep 15, 2021
0.0.3 Sep 15, 2021
0.0.1 Sep 14, 2021

#189 in Procedural macros

Download history 126/week @ 2021-10-02 89/week @ 2021-10-09 89/week @ 2021-10-16 65/week @ 2021-10-23 25/week @ 2021-10-30 33/week @ 2021-11-06 86/week @ 2021-11-13 149/week @ 2021-11-20 43/week @ 2021-11-27 165/week @ 2021-12-04 106/week @ 2021-12-11 108/week @ 2021-12-18 21/week @ 2021-12-25 138/week @ 2022-01-01 75/week @ 2022-01-08 83/week @ 2022-01-15

323 downloads per month
Used in descriptor

Apache-2.0

23KB
618 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

~0.4–0.8MB
~19K SLoC

RBa