Labeled Tab-separated Values (LTSV) format is a variant of Tab-separated Values (TSV). Each record in a LTSV file is represented as a single line. Each field is separated by TAB and has a label and a value. The label and the value have been separated by ':'. With the LTSV format, you can parse each line by spliting with TAB (like original TSV format) easily, and extend any fields with unique labels in no particular order.
rust
time:[10/Oct/2000:13:55:36 -0700]\tdone:true\tscore:-1\tmean:0.42\tcounter:42\tlevel:3\thost:testhostname\tname1:value1\tname 2: value 2\tn3:v3\tmessage:this is a test
You can start using it by first adding it to your Cargo.toml
:
toml
[dependencies]
serde_derive = "1.0"
serde_ltsv = "0.1"
Then, create a structure which implement serde::Serialize
/ serde::Deserialize
traits and
use the structure with any serde lib.
```rust
extern crate serdederive; extern crate serdeltsv; extern crate serdejson; extern crate serdeyaml;
struct Foo { a: String, b: i8, c: bool }
fn main() {
let t = Foo { a: "toto".into(), b: 8, c: true };
let strt = serdeltsv::tostring(&t).unwrap();
println!("As ltsv => {}", &strt);
let t2: Foo = serdeltsv::fromstr(&strt).unwrap();
println!("As json => {}", serdejson::tostringpretty(&t2).unwrap());
println!("As yaml => {}", serdeyaml::tostring(&t2).unwrap());
}
**Output**:
As ltsv => a:toto b:8 c:true
As json => {
"a": "toto",
"b": 8,
"c": true
}
As yaml => ---
a: toto
b: 8
c: true
```
License: BSD-3-Clause