Introduction
Repository stores code for Rust library that allows to read from and write to .io file format.
About
.io file is a text format that contains serialized object. Each object is stored between two vertical bars |X| in one line for primitive object or more, for iterables and structures. It is build to be cross-platform, language-independent and human-readable.
You can read more about .io de/serialization file format goal and mission here.
Functions and plans
The current status of both serialization and deserialization:
- Primitive types
- Strings
- Arrays
- Vectors
- Hashmaps
- Structs (Named{} and Tuple() and Unit-like)
- Generic objects ()
- Tuples
- &str type
- Slices
- Option
- Result
- Combinations of all above
- Enums (Unit, Unnamed(), Named{})
- Reference types (&T)
- Unit type
()
Full list of supported types can be found in this crate's documentation.
Capabilities
- Serialization of supported types using macro to_io!() using objects reference,
- Deserialization of supported types using macro from_io!() using .io formatted String and objects type,
- Renaming structs fields in and from .io formatted String using #[io_name()] helper macro using String literal as argument.
- Ordering structs fields in and from .io formatted String using #[io_order()] helper macro using either FIRST and LAST keywords or an i16 Integer.
- Ignoring public fields in de/serialization using #[io_ignore] helper macro
- Allowing to de/serialize private fields using #[io_allow] helper macro.
Refer to example to see, how these capabilities can be utilized and how they affect the serialized string.
How to use
First, you need to import iodeser crate. Inside of Cargo.toml add:
[]
# ...
= "0.6.0"
Next, you need to import crate in a code:
use *;
To serialize or deserialize ready objects use macros. Remember about passing desired objects type to deserialization macro.
// serialize
let number: i32 = 37;
let serialized_number = to_io!;
//deserialize
let deserialized_number = from_io!.unwrap;
assert_eq;
To de/serialize created structs or enums you need to use derive trait IoDeSer:
let animal = Animal;
let serialized_animal = to_io!;
let deserialized_animal = from_io!;
Example usage
use *; // required import
// required macro derive IoDeSer, Debug and PartialEq is not required
// required macro derive, Debug and PartialEq is not required
// required macro derive, Debug and PartialEq is not required
/*
Output:
|
Address->|
|
number->|
Numeric->|
|65|
|
|
street->|Tęczowa|
city->|Warsaw|
|
+
|
number->|
String->|
|220a|
|
|
street->|Strasse|
city->|Hamburg|
|
|
Name->|John|
SecondName->|||
LastName->|Kowalski|
Age->|21|
|
Person { name: "John", second_name: None, last_name: "Kowalski", age: 21, address: [Address { city: "Warsaw", number: Numeric(65), street: "Tęczowa" }, Address { city: "Hamburg", number: String("220a"), street: "Strasse" }] }
*/
See more examples on GitHub in examples.
Features
Optional features for now only include crate chrono.
To use it you need to turn on feature in Cargo.toml:
[]
# ...
= { = "0.6.0", = ["chrono"]}
You can either inclide chrono as a dependency in Cargo.toml or use it from iodeser package:
use *;