type_description

Bors enabled

This crate provides machine-readable descriptions for types.

The idea is to make types discoverable for users by explaining them in a way that a user can understand without knowing implementation details (a u16 is an "integer with 16 bit")

Example

One could make configuration types explained with this crate and show the explanation (in a GUI, web interface, some special config-editor) to the user.

```rust use typedescription::AsTypeDescription; use typedescription::TypeDescription; use typedescription::TypeKind; use typedescription::Sign;

/// A configuration

[derive(TypeDescription)]

struct Config { /// The bind address addr: std::net::SocketAddr,

/// The Port
port: u16,

}

let desc = Config::astypedescription();

asserteq!(desc.name(), "Config"); asserteq!(desc.doc(), Some("A configuration")); assert!(std::matches!(desc.kind(), TypeKind::Struct(_)));

match desc.kind() { TypeKind::Struct(v) => { let firstfield = &v[0]; asserteq!(firstfield.0, "addr"); asserteq!(firstfield.1, Some("The bind address")); asserteq!(firstfield.2.name(), "String"); asserteq!(firstfield.2.doc(), Some("A socket address")); asserteq!(*firstfield.2.kind(), typedescription::TypeKind::String);

    let second_field = &v[1];
    assert_eq!(second_field.0, "port");
    assert_eq!(second_field.1, Some("The Port"));
    assert_eq!(second_field.2.name(), "Integer");
    assert_eq!(second_field.2.doc(), Some("An unsigned integer with 16 bits"));
    assert_eq!(*second_field.2.kind(), type_description::TypeKind::Integer { size: 16, sign: Sign::Unsigned });
}
_ => unreachable!()

} ```

Goals

Non-Goals

License

MPL-2.0