#table #serde #serialization #csv

tsv

tsv (tab-seperated-values) data format for serde (serialization/deserialization)

2 releases

Uses old Rust 2015

0.1.1 Sep 26, 2018
0.1.0 Aug 16, 2018

#1997 in Encoding

Download history 10/week @ 2024-07-19 18/week @ 2024-07-26 21/week @ 2024-08-02 38/week @ 2024-08-09 46/week @ 2024-08-16 45/week @ 2024-08-23 43/week @ 2024-08-30 86/week @ 2024-09-06 123/week @ 2024-09-13 394/week @ 2024-09-20 474/week @ 2024-09-27 416/week @ 2024-10-04 269/week @ 2024-10-11 33/week @ 2024-10-18 47/week @ 2024-10-25 78/week @ 2024-11-01

518 downloads per month

MIT license

66KB
1.5K SLoC

The tsv project introduces a new format for data serialization/deserialization, which is text-based and deals with tabular data.

The problem

At serde's point of view, the classic tsv is only applicable to the schema of (a sequence of) a struct composed of primitives( integer, floats, strings etc). The specification has to be extended to allow arbitrary schemas, such as a struct of a struct.

The solution

This project extends the spec by placing sequences in columns. See tsv-spec.txt for specification. It uses serde crate for serialization/deserialization, and reflection crate for generating column names and dealing with enums.

Notice

If you impl Serialize/Deserialize for your types to tell serde they are sequences/maps, do make sure their schemata() and Vec::schemata()/HashMap::schemata() are isomorphic.

Pros

  1. Simple. The only requirement for end users to use tsv files is to understand what a table is. It is deadly simple as a configuration file format for non-technical users.

  2. Available. You can use Microsoft Excel, OpenOffice/LibreOffie Calc and text editors that support elastic tabstops to view/edit tsv files. And it is easy to write tsv by hand if you have read all the 63 lines of the spec.

Cons

  1. Not efficiency-oriented.

  2. Not self-descripting.

License

Under MIT.

Example

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.

Dependencies

~0.8–1.4MB
~30K SLoC