Describer
Helper crate that generates customizable Rust Structs describing strings.
Installation
[]
= "0.2"
Usage
Original syntax is inspired by GraphQL, reason why required fields end with
!.
Basic Structs:
Simple struct types will represent field_name: T as field_name: T!, while optional fields will represent optional_field_name: Option<T> as optional_field_name: T. Struct will be represented as StructName { field_name: T, .. }.
use Describe;
Unit Structs:
Unit struct will be represented just by the struct name, StructName:
use Describe;
;
Enum types:
Enum variants are represented in a traditional Set like representation inside a #{ <variants> }, so EnumName #{ VariantA, VariantB, .. }
use Describe;
Results and Vecs:
Results are explicitly represented, with Result<OK, ERROR>, while Vecs are represented, by default, inside [T]
use Describe;
Prettify Output
Hiding optional fields:
To hide optional fields you can add the attribute #[prettify(hide_opt = true)]. It only hides root field optionals:
use Describe;
Explicit Vec and linear collections:
Linear collections:
Vec<T>, HashSet<T>, BTreeSet<T>, indexmap::IndexSet<T>
To show linear collections explicit type #[prettify(explicit_collections = true)]. By default they are [T]:
use Describe;
Explicit key-value collections:
Key-value collections:
HashMap<K, T>, BTreeMap<K, T>, indexmap::IndexMap<K, T>
To show key-value collections explicit type #[prettify(explicit_collections = true)]. By default they are {K, T}:
use Describe;
use ;
use IndexMap;
Custom Separators and Spacing:
The default separator is ", " , the default spacing is " " and the default key-value (keyval) separator is ": " with tokens it is possible to change separator and spacing to the desired customization.
use Describe;
Hide Struct/Enum Name
To hide struct or enum name you can add the attribute #[prettify(hide_name = true)]:
use Describe;
Limitations:
- TupleStructs are not yet supported.
- Structured Enum Variants are not yet supported.
- Tuple Enum Variants are not yet supported.
- Non derivable types are not supported.
- Nested describing is not yet supported.