formattable-0.0.3 has been yanked.
formattable
Make it easy and ergonomic to provide formatted output.
Usage
Make sure you enable/disable the appropriate <#features> for the functionality you want.
Basic
use Format;
use Serialize;
// Have some data structure that can be serialized.
;
// Instantiate a Format variant. Format is Copy, so it's easy to use and pass
// around.
let fmt = Json;
// Write your data structure to a JSON string.
let foo = Foo;
fmt.to_string.unwrap;
clap Integration
use Parser;
use Format;
use Serialize;
/// Demonstrate how to use `formattable` in a `clap`-based CLI.
///
/// This example just dumps the CLI arguments themselves as the selected format.
Features
Unfortunately, not all the various serialization libraries used by formattable
support the same serialization capabilities. Therefore, depending on the enabled
features you may or may not have certain methods available on Format. When in
doubt, consult the docs.
- default [toml, json, yaml]
- clap - enables the
clapCLI integration - json - default; enables serialization to JSON
- yaml - default; enables serialization to YAML; disables
to_string_pretty - toml - default; enables serialization to TOML; disables
to_writer