descriptor

Crates.iodescriptor
lib.rsdescriptor
version0.0.4
sourcesrc
created_at2021-09-14 19:51:48.550596
updated_at2021-09-15 20:09:07.109406
descriptionA simple to use struct descriptor
homepage
repositoryhttps://github.com/XciD/descriptor
max_upload_size
id451419
size144,348
Adrien Carreira (XciD)

documentation

https://docs.rs/descriptor/

README

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));
}
Commit count: 5

cargo fmt