Crate tsv

Source
Expand description

§tsv (tab-seperated-values) library for serde (serialization/deserialization).

The tsv format is right out and uses human-readable text to interchange data of arbitrary schema.

§Example (Map)

extern crate tsv;

extern crate reflection;
use reflection::Reflection;
  
use std::collections::HashMap;

type Map = HashMap<String,u32>;
                                                                                      
let mut map = Map::new();
map.insert( "abcd".to_string(), 42_u32 );
map.insert( "efg".to_string(), 23_u32 );
                                                                                      
let str_repr = tsv::ser::to_string( &map, tsv::Config::default() ).unwrap();
let mut env = tsv::Env::default();
let map_from_str: Map = tsv::de::from_str( &str_repr, Map::schemata(), &mut env ).unwrap();
assert_eq!( map, map_from_str );

The str_repr( stands for “string representation” ) looks like something as follows( with spaces replacing tabs ):

name    value
abcd    42
def     23

§Example (Cargo.tsv)

A cargo configuration file written in tsv format could look like the following table( with spaces replacing tabs ):

                                        deps
package                         lib             value    
name    version authors keyword macro   name    Version Path
tsv     0.1.0   oooutlk tsv     X       serde   1.0
                        tab             trees           ~/trees
                        table
                        serde

See serialization example and deserialization example.

Re-exports§

pub use self::ser::Serializer;
pub use self::ser::to_string;
pub use self::de::Deserializer;
pub use self::de::from_str;
pub use error::Error;
pub use error::Result;

Modules§

de
Deserialize tsv to a Rust data structure.
error
When serializing or deserializing tsv goes wrong.
fs
File operations.
ser
Serialize a Rust data structure into tsv data.

Structs§

Config
A structure for configuring tsv serializer.
Env
A structure for configuring tsv deserializer and holding escaped Strings being referenced as &str by deserialized value, if any.