| Crates.io | serde_table |
| lib.rs | serde_table |
| version | 0.2.0 |
| created_at | 2025-01-20 01:06:33.197103+00 |
| updated_at | 2025-01-20 01:30:38.432485+00 |
| description | Write structs in an easy table format. |
| homepage | https://github.com/trenchant-dev/serde_table |
| repository | https://github.com/trenchant-dev/serde_table |
| max_upload_size | |
| id | 1523455 |
| size | 15,417 |
A macro for parsing tables into Rust structs.
use serde::Deserialize;
use serde_table::serde_table;
#[derive(Deserialize)]
struct Person {
name: String,
age: u32,
city: String,
}
let people: Vec<Person> = serde_table! {
name age city
John 30 NewYork
Jane 25 LosAngeles
}.unwrap();
Add the following to your Cargo.toml:
[dependencies]
serde_table = "0.1.0"
While serde_table ought to do the right thing in general,
you can use serde_table_expr if you need to avoid the automatic quoting of bare variable-names (identifiers).
When you're writing tests, have you ever felt the desire to hide the data off in a file? Or switch to ron?
This is because modern programming is preoccupied with the individual, not the batch. Here's a before, 153 characters.
vec![
Person {
name: "John".to_string(),
age: 50,
city: "NewYork".to_string(),
},
Person {
name: "Jane".to_string(),
age: derive_age(),
city: "LosAngeles".to_string(),
},
]
After, 88 characters. That is a 2x improvement in signal-to-noise.
let people: Vec<Person> = serde_table! {
name age city
John 30 NewYork
Jane derive_age() LosAngeles
}.unwrap();
You should read the (small) source for details, but the gist is that we translate what you wrote into a CSV string, then parse that with csv / serde. This can definitely be simplified, PRs welcome.