#io #file-format #deserialize #serialization #read-write #array

yanked io_de_ser

Crate that allows to read from and write to .io file format

3 unstable releases

0.1.2 Feb 3, 2024
0.1.1 Feb 3, 2024
0.0.3 Feb 3, 2024

#177 in #deserialization

MIT license

17KB
259 lines

Contains (Cab file, 14KB) .vs/rust-library/v17/.wsuo

About

Repository stores code for Rust library that allows to read from and write to .io file format.

Functions and plans

The current status of both serialization and deserialization:

  • Primitive types
  • Strings
  • Arrays
  • Vectors
  • Hashmaps
  • Structs (with named fields)
  • Generics
  • Combinations of all above
  • Tuples
  • Tuple structs
  • &str type
  • Slices

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 wanted objects type,
  • Only decorative! support for renaming fields in struct in and from .io formatted String using #[io_name()] helper macro using String literal as argument.

See example below for usage of those capabilities.

Example usage

use io_de_ser::*; // required import

#[derive(IoDeSer, Debug)] // required macro derive IoDeSer, Debug is not required
struct Person<T : IoDeSer> {
    #[io_name("Name")]		// optional renaming
    pub name: String,
    #[io_name("LastName")]	// optional renaming
    pub last_name: String,
    #[io_name("Age")]		// optional renaming
    pub age: u8,
    #[io_name("Address")]	// optional renaming
    pub address: Address<T>,
}

#[derive(IoDeSer, Debug)] // required macro derive, Debug is not required
struct Address<T : IoDeSer> {
    pub city: String,
    pub number: T,
    pub street: String,
}

fn main() {
    let person = Person::<u8>{
        name: "John".to_string(),
        last_name: "Kowalski".to_string(),
        age: 21,
        address: Address::<u8> {
            city: "Warsaw".to_string(),
            number: 65,
            street: "Tęczowa".to_string(),
        },
    };

    let io_serialization: String = to_io!(&person); // serialization by reference
    /* saving to file for example */
    println!("{}", &io_serialization);

    let person_deserialization : Person<u8> = from_io!(io_serialization, Person<u8>); // deserialization
    println!("{:?}", &person_deserialization);
}
/*
Output:
|
        Name->|John|
        LastName->|Kowalski|
        Age->|21|
        Address->|
                city->|Warsaw|
                number->|65|
                street->|Tęczowa|
        |
|
Person { name: "John", last_name: "Kowalski", age: 21, address: Address { city: "Warsaw", number: 65, street: "Tęczowa" } }
 */

Dependencies

~1.5MB
~38K SLoC