Crates.io | plod |
lib.rs | plod |
version | 0.4.0 |
source | src |
created_at | 2024-04-16 16:51:16.190395 |
updated_at | 2024-05-11 13:30:26.373698 |
description | Plod - deriving plain old data |
homepage | https://github.com/peckpeck/plod |
repository | https://github.com/peckpeck/plod |
max_upload_size | |
id | 1210442 |
size | 18,357 |
Plod is an easy to use plain old data reader and writer. It transforms them from and to natural rust types.
Plain old are were commonly designed to be used in C, but in rust we can have more meaningful datastructures for the same representation. For example, in C unions with a separate tag are the only way to represent the thing called enum that we have for grated in rust.
Since it uses the standard Read
and Write
traits, Plod can be used to read and write
binary files as well as network protocols as long as you have a reader or a writer.
Here is an example with a struct and an enum:
use plod::Plod;
#[derive(Plod)]
struct Value {
kind: u16,
value: u32,
}
#[derive(Plod)]
#[plod(tag_type(u8))]
enum ValueStore{
#[plod(tag=1)]
Series {
kind: u16,
#[plod(size_type(u16))]
values: Vec<u32> },
#[plod(tag=2,size_type(u16))]
Keys(Vec<Value>),
}
More documentation about #[plod]
attributes at Plod
Plod transforms a serialized plain old data into a ready to use plain Rust data-structure. It uses attributes to achieve that. This means that an enum or a vec can easily be read from a binary file.
Other reasons:
Read
and Write
traits.#[repr()]
Plod is for plain old data, which means that is well suited for known, existing, binary formats. But:
If you want a way to serialize your own data and be able to read it later, you should prefer serde which can serialize any data into many more formats that can be self describing.
If your file format is not binary and not easily supported by serde, you may look at nom for parsing it.
If your data only contains primary types and all you want is speed you may take a look at plain, pod and nue.
Plod use the obvious representation for struct as C does. However some data structure are not so obvious.
None
, the idea is that you can read a structure and
then add some more high level information to it by replacing Options with anything.Document endianness and it inheritance
How to call Plod trait methods
Example, tutorial, first use
License: MIT